Mysql – Check to see if an ID exists in a database

existsMySQL

When given an ID number, I want to check to see if it exists in the database. Return true if the ID is found and if not, then return false.

My knowledge of MySQL is very low, but I am assuming it would be something to do with the COUNT(*) function possibly?

Best Answer

select id from table where id = $id

No need to get fancy. Using exists with subqueries seems likely only to generate poor performance, but I'm happy to be corrected if shown otherwise.