logo

Back to questions

SQL WHERE AND Practice Exercise [SQL Interview Question]

Easy

Let's practice using along with to filter Amazon reviews based on all 4 of these conditions:

  1. the review should have 4 or more stars
  2. the review ID is less than 6000
  3. the review ID is more than 2000
  4. the review can't come from user 142

Pro Tip: Try coding up, and executing, each command, one at a time. It's too easy to try to code this all up in one go, and mess something up!

Table:

Column NameType
review_idinteger
user_idinteger
submit_datedatetime
product_idinteger
starsinteger (1-5)

Sample Input:

review_iduser_idsubmit_dateproduct_idstars
617112306/08/2022 00:00:00500014
458256206/15/2022 00:00:00125804
780226506/10/2022 00:00:00698524
529336206/18/2022 00:00:00500013
635219207/26/2022 00:00:00698523
451798107/05/2022 00:00:00698522

Sample Output:

review_iduser_idsubmit_dateproduct_idstars
458256206/15/2022 00:00:00125804

Review 4582 satisfies all 4 constraints!

PostgreSQL 14