mdance
mdance

Reputation: 996

SQL - Get rows with ID's that are between 5 and 10..

I'm new to SQL, and need to get the rows that have ID's greater/equal to 5 and less than/equal to 10. Is there SQL that can handle this, or should I use PHP?

Upvotes: 0

Views: 699

Answers (3)

phadaphunk
phadaphunk

Reputation: 13283

Thats the cool thing about SQL. Its syntax is close to our language. You see I pretty much typed exactly what you asked for.

Select * From youTable
Where Id >= 5 AND Id <= 10

Also in T-SQL the BETWEEN operator would include Both 5 and 10 and do the exact same thing as the previous example. From there it's your choice.

Select * From yourTable
Where Id BETWEEN 5 AND 10

Upvotes: 2

Taryn
Taryn

Reputation: 247650

You can use greater than or less than in your WHERE clause.

SELECT * 
FROM yourTable
WHERE Id >= 5 AND ID <= 10

Upvotes: 2

Bort
Bort

Reputation: 7618

Easiest would be to use BETWEEN

SELECT * FROM theTable
WHERE Id BETWEEN 5 AND 10

Upvotes: 3

Related Questions