Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 选择表中的列与另一个表中的列不同的数据_Sql - Fatal编程技术网

Sql 选择表中的列与另一个表中的列不同的数据

Sql 选择表中的列与另一个表中的列不同的数据,sql,Sql,我需要从一个表(表1)中选择数据,其中一个特定列与另一个表(表2)中的另一列不同 诸如此类: SELECT * FROM table1 WHERE table1.column1 != table2.column2 我是这样做的: SELECT * FROM table1 inner join table2 on table1.id = table2.id WHERE table1.column1 != table2.column2 我有一个表(表1),我存储了一些人。我需要一个接一个地随机

我需要从一个表(表1)中选择数据,其中一个特定列与另一个表(表2)中的另一列不同

诸如此类:

SELECT * FROM table1 WHERE table1.column1 != table2.column2

我是这样做的:

SELECT * FROM table1
inner join table2 on table1.id = table2.id
WHERE table1.column1 != table2.column2
我有一个表(表1),我存储了一些人。我需要一个接一个地随机选择并添加到另一个表(表2)。如果添加了一个人,则可以再次选择该人,直到所有人都被选中。这是我的疑问:

SELECT * FROM people inner join people_generated on people.id = people_generated.id WHERE people.id != people_generated.id_people ORDER BY RAND() LIMIT 1 
返回一个空结果:“MySQL返回一个空结果集”


第二个表“people\u genrated”是空的,所以,保留people来生成。为什么结果是空的?

试试这样的方法

SELECT t1.name FROM table1 t1
LEFT JOIN table2 t2 ON t2.name = t1.name
WHERE t2.name IS NULL
试试这个

SELECT * FROM table1
inner join table2 on table1.id = table2.id
WHERE table1.column1 != table2.column2
试试这个

 Select rooms.single from rooms where rooms.single<>checkin.room_no;
从rooms.singlecheckin.room\u no;

你能解释一下为什么要使用
左连接吗?@HamletHakobyan,连接更改为内部连接,谢谢!