mercredi 2 mars 2016

SQL or statement vs multiple select queries

I'm having a table with an id and a name. I'm getting a list of id's and i need their names.

In my knowledge i have two options.

Create a forloop in my code which executes:

SELECT name from table where id=x

where x is always a number.

or I'm write a single query like this:

SELECT name from table where id=1 OR id=2 OR id=3

The list of id's and names is enormous so i think you wouldn't want that.

What's a nice solution for this problem?

Aucun commentaire:

Enregistrer un commentaire