下面的查詢,是爲了尋找不另一個表相等的相應選民的ID記錄..PHP MySQL的JOIN確定不等於記錄
SELECT *
FROM electors,voting_intention
WHERE electors.ID != voting_intention.elector
這應該在這個FIDDLE返回1個記錄http://sqlfiddle.com/#!3/0a4b1/10但返回很多並帶有重複項。顯然我錯過了一些東西。什麼?
下面的查詢,是爲了尋找不另一個表相等的相應選民的ID記錄..PHP MySQL的JOIN確定不等於記錄
SELECT *
FROM electors,voting_intention
WHERE electors.ID != voting_intention.elector
這應該在這個FIDDLE返回1個記錄http://sqlfiddle.com/#!3/0a4b1/10但返回很多並帶有重複項。顯然我錯過了一些東西。什麼?
如果您希望找到所有沒有相應「投票意向」記錄的選民,請嘗試以下操作。我假設你想要這個選民的所有領域。如果不是,您需要選擇感興趣的列。
select * from
electors where id not in
(select elector from voting_intention)
好,但得到選民的所有發生,所以它只產生elector.ID 4但4次,因爲有4個voting_intention行在小提琴。 – user1490367
那麼,我只得到一個記錄。你可以使用distinct來獲得一行。請查看http://sqlfiddle.com/#!2/ea2ce/1/0 –
SELECT *
FROM voting_intention
RIGHT JOIN electors ON electors.ID = voting_intention.elector
WHERE voting_intention.elector IS null
如果你會得到的選舉人ID 4的記錄?另外,你的小提琴目前被設置爲Sql Server。 –
是的,因爲這是唯一的elector.ID不等於任何voting_intention.elector – user1490367