Solved

SQL Select Query Issue

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle DB monitor SW 21 48
Whats wrong in this query - Select * from tableA,tableA 11 31
Tsql query 6 21
optimize stored procedure 6 25
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

770 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