Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
261 Views
Last Modified: 2012-05-11
select customerid, city, dateordered where customerid = (select customerid, city, max(dateordered)
0
Comment
Question by:Jimmy_inc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Assisted Solution

by:Rikin Shah
Rikin Shah earned 125 total points
ID: 35135504
Try this...

select customerid, city, dateordered from <tablename> where customerid in (select customerid from <tablename> having max(dateordered))
0
 

Author Comment

by:Jimmy_inc
ID: 35135513
Yes that looks better, I will try this
0
 
LVL 41

Accepted Solution

by:
Sharath earned 125 total points
ID: 35135551
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
 
LVL 5

Assisted Solution

by:Angelgeo
Angelgeo earned 125 total points
ID: 35136300

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
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 125 total points
ID: 35139240
See attached.
query.txt
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question