help needed with Microsoft SQL Server syntax

select customerid, city, dateordered where customerid = (select customerid, city, max(dateordered)
Jimmy_incAsked:
Who is Participating?
 
SharathData EngineerCommented:
try this.
SELECT customerid, 
       city, 
       dateordered 
  FROM your_table t1 
 WHERE t1.dateordered = (SELECT MAX(t2.dateordered) 
                           FROM your_table t2 
                          WHERE t1.customerid = t2.customerid 
                                AND t1.city = t2.city)

Open in new window

0
 
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Try this...

select customerid, city, dateordered from <tablename> where customerid in (select customerid from <tablename> having max(dateordered))
0
 
Jimmy_incAuthor Commented:
Yes that looks better, I will try this
0
 
Kakhaber SiradzeCommented:

select 
  customerid, city, max(dateordered) as dateordered
from
  tablename
group by customerid, city

-- Or 

select 
  customerid, city, dateordered
from
  tablename
where 
  dateordered in (select max(dateordered) as dateordered
from
  tablename)

Open in new window

0
 
awking00Commented:
See attached.
query.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.