您好!我需要帮助,我有一个具有此值的表
Table1
sorter | valuedata | status | useraccounts |
----------------------------------------------
same | value1 | Disabled | user1 |
same | value2 | Active | user1 |
和
Table2
name | useraccounts |
-------------------------
user1 | displayname1 |
我希望显示所有数据,即使它们具有不同的状态,而它们是像这样的内连接
SELECT table1.name,table2.useraccounts
FROM table1 INNER JOIN table2 ON table1.useraccounts = table2.name
WHERE table1.sorter = "same" AND table1.status = "Disabled" AND table1.status != "Disabled"
这甚至可以做到吗?
答案 0 :(得分:0)
实际上,您需要交叉连接。你也可以在不使用JOIN的情况下编写它:
SELECT table2.name,table2.useraccounts
FROM table1,table2 WHERE table1.useraccounts = table2.name
AND table1.sorter = "same"
答案 1 :(得分:0)
我认为你犯了两个错误:
接下来就是我认为你在寻找的东西:
SELECT table2.[name],table2.useraccounts
FROM table1 INNER JOIN table2 ON table1.useraccounts = table2.name
WHERE table1.sorter = 'same' AND
(table1.status = 'Disabled' OR table1.status != 'Disabled')
这可以改写为下一个,因为检查'Disabled'或!='Disabled'是ALL ROWS。
SELECT table2.[name],table2.useraccounts
FROM table1 INNER JOIN table2 ON table1.useraccounts = table2.name
WHERE table1.sorter = 'same'
答案 2 :(得分:0)
SELECT table2.name,table1.useraccounts
FROM table1 INNER JOIN table2 ON table1.useraccounts = table2.name
当状态不同时,U将获得所有数据