Antariksh Mishra
Antariksh Mishra

Reputation: 3

I want to pull distinct values for 2 columns in the same table and associated unique value columns for these unique values in SQL

The table is something like:

User_id      Bidid        timestamp ... (about 25-30 more columns)

How do I pull all the distinct user ids with all the distinct Bidid's associated with them and also the timestamp which is unique to each Bidid?

Upvotes: 0

Views: 34

Answers (2)

J_P
J_P

Reputation: 781

I think this could be idea you are looking for, it depends of the version SQL/environment/etc:

 SELECT USER_ID, BIDID, TIMESTAMP, ...
 FROM THE_TABLE
 WHERE BIDID=(SELECT DISTINCT BIDIT FROM THE_TABLE)

or

 SELECT USER_ID, BIDID, TIMESTAMP,..
 FROM THE_TABLE
 WHERE BIDID IN (SELECT DISTINCT BIDIT FROM THE_TABLE)

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270873

select distinct comes to mind:

select distinct User_id, Bidid, timestamp 
from t;

Upvotes: 2

Related Questions