Solved

SQL Select Query Issue

Posted on 2013-01-23
3
222 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 142

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now