0

I am new to sql and today my manager asked me to retrieve some customres informations using their customer ID so i used the following query:

SELECT * 
FROM Customers
WHERE CustID = “11023” or CustID = “11045” or CustID = “11001” or CustID = “101989”;

It did work but i wonder if there is a better way to do it.

1
  • "better way to do it" -- better in what way?
    – mustaccio
    Commented Jul 8, 2021 at 11:51

1 Answer 1

2

Better is a relative term as different people will have different opinions got different engines. That said, a simpler method to search for multiple records using the same column would be IN. Your query would look something like this:

SELECT * 
  FROM Customers
 WHERE CustID IN ("11023", "11045", "11001", "101989");

This makes it a little easier to write queries that can look up any number of customers by ID.

Not the answer you're looking for? Browse other questions tagged or ask your own question.