我想从表 1 中选择所有行,其中第 1 列或第 2 列中有 smith 且状态为 1。
如果第1列有smith,则从第2列取值,如果第2列有smith,则取该行第1列的值。
然后从表 2 中选择所有在表 2 的 column1 或 column2 中包含该值的行(我们通过从表 1 中选择得到。)
最佳答案
这应该涵盖#1/2,你已经把我弄丢了#3
select if(col1 = 'smith', col2, col1) from table1
where (col1 = 'smith' or col2 = 'smith') and status = 1
关于带有选择的mysql复杂查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3090543/