所以我的問題是讓我說我有3個表:「customerPerAdmin」,「管理員」,「客戶」 和我加入他們,但如果,customerPerAdmin.AdminID會爲某個用戶設置爲0? 會發生什麼,它會忽略與adminID等於零的客戶,我不希望發生這種情況,我想將admins.FirstName和admin.LastName設置爲空。SQL與空數據檢索沒有聯繫表
customerPerAdmin表:
ID AdminID CustomerID
40 20 49
41 25 48
42 20 50
43 0 51
,這是查詢
SELECT SQL_CALC_FOUND_ROWS `customers.UniqID`,
`customerPerAdmin`.`AdminID`,
`customerPerAdmin`.`CustomerID`,
`customerPerAdmin`.`IsDeleted`,
`customerPerAdmin`.`pr`,
`admins`.`ID`,
`admins`.`GroupID`,
`admins`.`FirstName` AS adminFirstName,
`admins`.`LastName` AS adminLastName,
`admins`.`IsDeleted`,
`customers`.`FirstName`,
`customers`.`LastName`,
`customers`.`Phone`,
`customers`.`Email`,
`customers`.`GroupID`,
`customers`.`UniqID`,
`customers`.`Created`,
`customers`.`IsDeleted`,
`customers`.`ID`
FROM (`customers`)
JOIN `customerPerAdmin` ON `customers`.`ID`=`customerPerAdmin`.`CustomerID`
JOIN `admins` ON `admins`.`ID`=`customerPerAdmin`.`AdminID`
AND `customers`.`GroupID` = '8'
AND `customerPerAdmin`.`pr` = 0
GROUP BY `customers`.`ID`
ORDER BY `customers`.`ID` DESC LIMIT 20
所以會發生什麼,那隻能說明我的40,41,42的ID,而不是43,因爲他不能將它與ID爲0的管理員關聯,因爲他不存在。 即使它不相關,我仍然可以顯示ID 43?
在此先感謝。
變化 – 2014-03-18 20:38:58
太感謝你了!工作!,你能給我更詳細的關於外部和內部連接的解釋嗎?因爲我真的不明白他們 – Bonik
http://clip2net.com/s/72syyq – KrazzyNefarious