PostgreSQL IN

Let's first look at two query statements:

SELECT customer_id,
	rental_id,
	return_date
FROM
	rental
WHERE
	customer_id IN (1, 2)
ORDER BY
	return_date DESC;
SELECT
	rental_id,
	customer_id,
	return_date
FROM
	rental
WHERE
	customer_id = 1 OR customer_id = 2
ORDER BY
	return_date DESC;

The results returned by the two query statements are the same, but the execution of IN is much faster than OR or AND, so the first way of writing is more recommended.

NOT IN means that it is not in a certain range. The
back of IN can be a list of values ​​returned by the subquery

Guess you like

Origin blog.csdn.net/weixin_42072754/article/details/109635922