0
這裏是我的select語句:在SQL選擇忽略列
SELECT DISTINCT
ms.createdon
,c.new_memberid
,c.firstname
,c.lastname
,c.new_primaryclubname
,a.line1
,a.city
,a.stateorprovince
,a.postalcode
,c.telephone1
,c.telephone2
,c.birthdate
,c.gendercodename
,p.ProductNumber
,mr.new_backgroundcheckflagname
,c.emailaddress1
,c.new_divisioncode
,c.emailaddress2
FROM
Filterednew_membershiprequirement AS mr
LEFT JOIN Filteredcontact AS c ON mr.new_contact = c.contactid
LEFT JOIN FilteredCustomerAddress AS a ON c.contactid = a.parentid
INNER JOIN Filterednew_membership AS ms ON c.contactid = ms.new_contact
INNER JOIN Product AS p ON ms.new_product = p.ProductId
WHERE
c.new_divisioncode = 'I' AND c.new_memberid= '123465789'
我對Filterednew_membership
列,是造成我的問題,因爲它有一個自動編號,這意味着每次被使用時,它會產生唯一的標識符,即使每個其他數據字段都是相同的。我如何告訴SQL忽略這一列,以便將其他字段只作爲一行而不是多行?
所以我越來越:
CreatedOn | MemberId | Full Name | ProductNum | EVILUNIQUEID
-------------------------------------------------------
01/01/01 | 12345678 | Bobb Ross | 10000 | 1
01/01/01 | 12345678 | Bobb Ross | 10000 | 2
01/01/01 | 12345678 | Bobb Ross | 10000 | 3
01/01/01 | 12345678 | Bobb Ross | 10001 | 4
而我想要的是:
CreatedOn | MemberId | Full Name | ProductNum
---------------------------------------------
01/01/01 | 12345678 | Bobb Ross | 10000
01/01/01 | 12345678 | Bobb Ross | 10001
你選擇'distinct',不包括'eviluniqueid',所以你應該沒問題。雖然你的查詢不符合你的結果,所以誰知道真正發生了什麼.. – Blorgbeard