sauero
sauero

Reputation: 259

Check if there is a table in the database - always returns 0

I need to check whether a given table, more specifically two are in the database, for this I have written such SQL command

SELECT COUNT(*) as number
FROM information_schema.tables
WHERE table_schema = "__pricelist_countries"
  AND table_schema = "__pricelist_ranges"

Unfortunately - although a table with this name is present in my database, SQL always returns 0 rows, which in turn causes the same condition to occur in PHP. Hence the question - how do I make a mistake, or how can I otherwise construct a command to be correct and return the result, or is this table actually or not?

Upvotes: 0

Views: 44

Answers (1)

Serkan Arslan
Serkan Arslan

Reputation: 13393

You should use OR

SELECT COUNT(*) as number 
FROM information_schema.tables 
WHERE table_schema = '__pricelist_countries' 
   OR table_schema = '__pricelist_ranges'

Upvotes: 2

Related Questions