I have a query like this:
SELECT c1 from t WHERE c2 IN list1 AND c3 IN list1;
I want to combine this query to get something like this:
SELECT c1 from t WHERE c2 AND c3 IN list1;
You can use arrays and the operator <@(contained) , for example:
<@
with my_table(name1, name2) as ( values ('Emily', 'Bob'), ('Ben', 'Jack'), ('Emily', 'James') ) select * from my_table where array[name1, name2] <@ array['Emily', 'Jack', 'James', 'Chloe']; name1 | name2 -------+------- Emily | James (1 row)
See also: How to use the same list twice in a WHERE clause?
Suppose one Person table has Code and Email columns, so you can join this table with the list you want to iterate over.
*P(('0000000264', 'luiza@gmail.com'), ('0000000262', 'ricardo@gmail.com'))L (, )cod = P.code AND mail = P.email
Source: https://habr.com/ru/post/1672348/More articles:Getting variable name in Java - javaHow to get current user profile picture using Keycloak? - javascriptWPF binding to combobox - c #Get a unique session id in the encoder - phpxcodebuild build-for-testing против действий сборки - xcodeLaravel - How to get a guard who authenticated the user? - laravelTI sensortag CC2650 with Kura Example - osgiC # Compare two objects for properties with different values - objectWhat is the default scope for a component created by @Produces without annotating the scope? - javaSharing a location using Whatsapp from my app - androidAll Articles