Tim N.
Tim N.

Reputation: 291

Simple MySQL SELECT/IF, to return if a number is over threshold?

I am creating a service where a user may only log in 5 times maximum before requiring a new account, how may I verify the count (assuming it is stored in a tinyint column named tries efficiently without requiring fetching of any columns?

In pseudocode:

SELECT FROM table WHERE userid=$uid AND tries <= 5

But it appears I need to select something regardless of if I need to return something or not. Is there a way to compare if tries <= 5 without selecting? I wish to rely on mysql_num_rows to check if their account is still valid or not if possible instead of comparing the number in PHP.

Upvotes: 0

Views: 435

Answers (2)

The Scrum Meister
The Scrum Meister

Reputation: 30111

SELECT 1 FROM table WHERE ...

Upvotes: 1

bensiu
bensiu

Reputation: 25564

SELECT COUNT(*) AS answer FROM ...

will return minimal info where 0 can be false, >0 true

Upvotes: 0

Related Questions