我想将表中一列中的最后一个值与另一个表中列中的每个值进行比较。经过多次尝试似乎无法实现它。
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 |
+---------+---------+
答案 0 :(得分:1)
您可以使用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))