?
Solved

SQL Select Query Issue

Posted on 2013-01-23
3
Medium Priority
?
232 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:Murray Brown
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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:Murray Brown
ID: 38810084
thanks very much
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

801 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