关于 php:SELECT all Values from a row with distinct values from a column

SELECT all Values from a row with distinct values from a column

id | order_id |跟踪 |状态 |更新时间

表名:ndc

1 100204835 124124304 0 2017-06-29 00:00:00

2 100204874 124104482 0 2017-06-29 00:00:00

3 100204835 124124304 0 2017-06-29 00:00:00

我需要从 ndc 中选择所有值(id、order_id、tracking_no),其中 order_id 应该是唯一的,因为可能存在重复值。

The result should output all values in the row as I need to use them further.

例如。在上表中 order_id 100204835 是重复的。


试试这个:Select * from ndc group by order_id;


没有一个答案对我有用,所以这是我正在工作的一个。在 col4 上使用 group bu,同时获取其他列的最大值

1
2
3
4
5
select max(col1) as col1,max(col2) as col2,max(col3) as col3
  , col4
  from
    table1
  group by col4

QUERY:

1
  SELECT id,order_id,tracking_no,status,update_time, DISTINCT order_id FROM ndc;

或者你可以使用简单的group by order_id;

语法:select * from table_name group by field_name;

NOTE: A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs.


您需要将 DISTINCT 与字段名称一起使用并指定其他字段。

SQL:SELECT DISTINCT order_id, id,tracking,status,update_time FROM table

更多大陆答案请关注-
MySQL - 选择所有列,其中一列是 DISTINCT


SELECT DISTINCT order_id,id,tracking_no FROM ndc;

also you can use it for distinct on multiple column

1
2
3
4
5
SELECT DISTINCT order_id  FROM ndc
UNION
SELECT DISTINCT id  FROM ndc
UNION
SELECT DISTINCT tracking_no FROM ndc

使用这个

1
Select * from table group by order_id;