WHERE statement with multiple conditions


I’m trying to select two items in my where statement. Can somebody tell me what’s wrong with this line of code?

$sql=" SELECT * FROM `explore` WHERE mschool='KMS' OR 'VB' ORDER BY mschool"

It isn’t pulling entries from my database with the entry “VB”. Obviously, I’m new to PHP and I thank all of you for this great website!

Thread moved to General Databases.

In the WHERE clause of a SQL query, you’ll always need to keep the following consistency:

field = value

So your query’s WHERE clause would look like:

WHERE mschool = ‘KMS’ OR mschool = ‘VB’

For comparing a single field against multiple values though, most SQL engines offer a more efficient construction:

WHERE mschool IN (‘KMS’, ‘VB’)

Not sure if that is spelled right like that, better check the manual on that one.

Sponsor our Newsletter | Privacy Policy | Terms of Service