I would like to make sure that a certain user isn’t existing already in my system. I have two tables:
- one with the confirmed users (xymply_users)
- one with the unconfirmed users (xymply_newusers).
I want to check the guy that’s signed up right now has selected a username not already in either of the tables. I tried this:
SELECT * FROM xymply_users, xymply_newusers
WHERE xymply_users.user ='test'
OR xymply_newusers.user ='test'
but if there’s a user ‘test’ in xymply_users it won’t show up with this query, why not I’m wondering?
Use a
UNION!Will give 1 record if the user exists, 2 records if it exists in both, no records if the user doesn’t exist.
SELECT 1is just an optimization; it’s faster thanSELECT *(SELECT *is usually always wrong)