Solved

SQL Select Query Issue

Posted on 2013-01-23
3
229 Views
Last Modified: 2013-01-23
Hi

I have a SQL query that brings up two lines for the same invoice
How would I do a further Select on this that only shows the first date

Supplier      Ref      Total      Due      Date
boston breweries      28924      4 990.34      4 990.34      2012/12/30
boston breweries      28924      4 990.34      4 990.34      2013/01/17
0
Comment
Question by:murbro
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38809353
please read up this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_3203-DISTINCT-vs-GROUP-BY-and-why-does-it-not-work-for-my-query.html

it will explain that you just have to clarify the rule on which row you want to show up (in your case, which "date" to choose), and formulate the sql accordingly
0
 
LVL 18

Expert Comment

by:deighton
ID: 38809472
SELECT * FROM (SELECT DQ.*, row_number() OVER(PARTITION BY DQ.supplier,    DQ.Ref,   DQ.Total,   DQ.Due ORDER BY DQ.date)  AS ROWN
FROM (<your exisitng query here>) DQ) DQ2
WHERE DQ2.ROWN=1
0
 

Author Closing Comment

by:murbro
ID: 38810084
thanks very much
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a step to a system backup job 6 19
Acces SQL Insert Problem 6 32
Run Stored Procedure uisng ADO 5 21
SQL Availablity Groups List 2 8
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

839 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