sKunKbad Posted November 17, 2008 Share Posted November 17, 2008 MySQL client version: 5.0.45 Simplified for the question: CREATE TABLE `admins` ( `username` varchar(12) NOT NULL ) CREATE TABLE `users` ( `username` varchar(12) NOT NULL, ) SELECT users.username, admins.username FROM users, admins WHERE users.username = 'skunk' OR admins.username = 'skunk' I'm just trying to see if the username 'skunk' belongs to either an admin or a user, but I get a result set like this: username username skunk admin1 skunk admin2 skunk admin3 How can I make this query just return one row that matches 'skunk' and that's it. Like this: username skunk Quote Link to comment https://forums.phpfreaks.com/topic/133035-solved-select-once-from-one-table-but-not-both/ Share on other sites More sharing options...
Mchl Posted November 17, 2008 Share Posted November 17, 2008 SELECT u.username FROM users AS u WHERE u.username ='skunk' UNION SELECT a.username FROM admins AS a WHERE a.username ='skunk' It could work without aliases I believe (users AS u...) Quote Link to comment https://forums.phpfreaks.com/topic/133035-solved-select-once-from-one-table-but-not-both/#findComment-691902 Share on other sites More sharing options...
sKunKbad Posted November 17, 2008 Author Share Posted November 17, 2008 Perfect! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/133035-solved-select-once-from-one-table-but-not-both/#findComment-692187 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.