[thelist] SQL help
Joshua Olson
joshua at waetech.com
Fri Jan 21 07:56:47 CST 2005
> -----Original Message-----
> From: Tim Burgan
> Sent: Friday, January 21, 2005 2:11 AM
>
> is this the correct SQL to seach if a username already exist
> across two
> tables, both containing id (unique number) and username
> (unique string)
> fields?
Tim.
I saw other responses, but try this.
Assuming that you want to return a record if the username exists it at least
one of the tables:
SELECT id
FROM tblStaff
WHERE username = '$username'
UNION ALL
SELECT id
FROM tblStudents
WHERE username = '$username'
If that returns at least one row, then you'll know the username exists in
one of the tables.
I suggest UNION ALL instead of UNION because it is faster--it doesn't remove
duplicates.
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168
More information about the thelist
mailing list