Sign in to follow this  
RockyBhai

Sql Help Please

Recommended Posts

RockyBhai


I have Sno, ID, DateTime, X, Y, Z Columns in my table. Sno is unique and  ID column will have duplicates.

I want to query all Distinct ID’s with latest DateTime.

 

Appreciate your help!

 

Share this post


Link to post
Share on other sites
LungiLingaraju

Group by ID and max(date) .... 

 

mention the  database you are using .. 

Share this post


Link to post
Share on other sites
Spartan
6 minutes ago, RockyBhai said:


I have Sno, ID, DateTime, X, Y, Z Columns in my table. Sno is unique and  ID column will have duplicates.

I want to query all Distinct ID’s with latest DateTime.

 

Appreciate your help!

 

https://www.w3schools.com/sql/sql_distinct.asp

SELECT DISTINCT column1, column2, ...
FROM table_name;

SELECT DISTINCT column1, column2, ...
FROM table_name; 

 

Share this post


Link to post
Share on other sites
RockyBhai

Thanks bro below worked

select distinct ID, max(DateTime) from tablename group by id order by max(DateTime) desc, ID

Share this post


Link to post
Share on other sites
RockyBhai
20 minutes ago, LungiLingaraju said:

Group by ID and max(date) .... 

 

mention the  database you are using .. 

Sql. Thanks for your time bro

Share this post


Link to post
Share on other sites
Picheshwar
22 minutes ago, RockyBhai said:

Thanks bro below worked

select distinct ID, max(DateTime) from tablename group by id order by max(DateTime) desc, ID

group by vadutunnav.. dISTINCT endhuku bokka

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this