• Advertisement
Sign in to follow this  

SQL cmd

This topic is 4790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

SELECT username FROM users WHERE username=genjix
how can i get this to just simply output the first match (i.e just see if any users have username genjix)?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you should always use COUNT() for these kind of queries like

select COUNT(*) from users
WHERE username='genjix';

and then simply check if the returned value is > 0. this will normally give you the best performance.

Share this post


Link to post
Share on other sites
I'm guessing you are trying to figure out if some users have the same username?

To simply determine if the username is already being used do this
if exists (SELECT username FROM users WHERE username=genjix)
select 1
else
select 0

You can also simply get the count
select count(*) username from users where username=genjix
If 0 then it's not being used. If > 1 then you've got multiple people with the same name.

Are usernames unique in your database? If so then your original query will also return the first one it finds because it will be the only one.

Hope this helps,
Webby

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement