Jump to content
  • Advertisement
Sign in to follow this  

SQL cmd

This topic is 5427 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
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
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,

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!