我是SQL的新手,我正在编写此查询
SELECT
SalesreturnDetails.[Price]
FROM
SalesreturnDetails,
SalesReturn
WHERE
SalesReturn.Session='12-13';
但在SalesReturn表中有两个记录,而SalesreturnDetails表有3个记录,但输出有6行,但我想输出应该是3行。
表格是: SalesReturn
Bill_Number Session
2 12-13
2 12-13
SalesReturnDetails
Bill_Number Price
2 700
2 900
2 300
答案 0 :(得分:1)
您应该在Bill_Number上尝试外部联接:http://en.wikipedia.org/wiki/Join_(SQL)
答案 1 :(得分:0)
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