Ankur Gupta
Ankur Gupta

Reputation: 963

fetch Single column from two table

I am very new in SQL and I am writing this query

SELECT
    SalesreturnDetails.[Price]
FROM
    SalesreturnDetails,
    SalesReturn
WHERE
    SalesReturn.Session='12-13';

but in SalesReturn Table there are two record and SalesreturnDetails table have 3 record but output is coming 6 rows but I want output should be 3 rows.

Tables are: SalesReturn

Bill_Number    Session
 2              12-13
 2              12-13

SalesReturnDetails

Bill_Number    Price
  2             700
  2             900
  2             300

Upvotes: 1

Views: 151

Answers (2)

muehlbau
muehlbau

Reputation: 1917

You should try an outer join on Bill_Number : http://en.wikipedia.org/wiki/Join_(SQL)

Upvotes: 1

John Woo
John Woo

Reputation: 263733

SELECT  a.Price
FROM    SalesReturnDetails a
        INNER JOIN 
        (
            SELECT  DISTINCT Bill_number
            FROM    SalesReturn
            WHERE   Session='12-13'
        ) b ON a.Bill_number = b.Bill_number

Upvotes: 0

Related Questions