1

id | order_id | tracking | status | update_time


Table Name : 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


I need to SELECT all values (id,order_id,tracking_no) from ndc where order_id should be unique as there might be duplicate values.

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

For Ex. In the above table order_id 100204835 is duplicate.

Alpha
  • 321
  • 6
  • 16

6 Answers6

1

Try this : Select * from ndc group by order_id;

Raju Singh
  • 455
  • 1
  • 6
  • 15
0

use this

Select * from table group by order_id;
Sagar V
  • 12,158
  • 7
  • 41
  • 68
Babuji
  • 1
0

SELECT DISTINCT order_id,id,tracking_no FROM ndc;

also you can use it for distinct on multiple column

SELECT DISTINCT order_id  FROM ndc
UNION 
SELECT DISTINCT id  FROM ndc
UNION
SELECT DISTINCT tracking_no FROM ndc
Reena Mori
  • 647
  • 6
  • 15
0

You need to use DISTINCT with a field name and specifying other fields.

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

For more continent answer please follow- MySQL - SELECT all columns WHERE one column is DISTINCT

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

QUERY:

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

or You Can Use Simple group by order_id;

Syntax: 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.

RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36
0

none of the answers worked for me so here is one that i got working. use group bu on col4 while taking max values of other columns

select max(col1) as col1,max(col2) as col2,max(col3) as col3
  , col4
  from 
    table1
  group by col4
Khan M
  • 415
  • 3
  • 17