我想将一个表中一列中的最后一个值与另一个表中该列中的每个值进行比较。多次尝试似乎无法实现。
Something like that: In this case I want to compare Value 3 with every value in column 4.
Table_1:
+---------+---------+
| column1 | column2 |
+---------+---------+
| value1 | value4 |
| value2 | value5 |
| value3 | value6 |
+---------+---------+
Table_2
+---------+---------+
| column3 | column4 |
+---------+---------+
| value7 | value10 |
| value8 | value11 |
| value9 | value12 |
+---------+---------+
最佳答案
您可以使用 max 来使用子选择
select * from Table_2
where Table_2.column4 = (select max(column1) from table_1 )
或使用顺序
select * from Table_2
where Table_2.column4 = (select column1 from table_1 order by column1 DESC limit 1)
或者使用 max(id)
select * from Table_2
where Table_2.column4 = (select column1 from table_1 having id = max(id))
关于mysql - 如何比较两个单独表中两列的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37977079/