简体   繁体   中英

IN statement multiple columns

I want to implement the below query

Select * from table1
where a in(select a,b,c,d,e from table2 order by date desc limit 5)

But IN statement is allowing only 1 column.

You can use the where clause in following

Select * from table1
where (a,a,a,a,a) in(select a,b,c,d,e from table2 order by date desc limit 5)

The fact that you need to do this suggests your design could use a rethink. But assuming the goal is to compare "a" from table1 separately to each column's value for table2, you can do it like this:

 ... in (select unnest(array[a,b,c,d,e]) from (select * from table2 order by date limit 5) foo )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM