MySQL: SELECT 0 FROM....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

MySQL: SELECT 0 FROM....

Post by Skara »

I think in Oracle you can do a 'select 0' thing. I'm not familiar with the language, so I'm not sure.

Anyway, I just want to check if something is in a database. Erhm.. basically...

Code: Select all

| 2 | 3 |
| 3 | 3 |
| 5 | 1 |
| 3 | 7 |

Code: Select all

SELECT ??? FROM table WHERE row1='5' AND row2='1';
...if (mysql_num_rows()), do whatever
Should I put something different where the ??? are, or should I just put 'row1' there?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

SELECT COUNT(*) AS count FROM table WHERE ....
Now, count will tell you how many entities there are that meet your criteria..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

if your using COUNT then you actually have to fetch `count`, rather than mysql_num_rows().
Post Reply