'Select COUNT (*) fails if no result

I'm trying to do a simple query (below) to see if there are no rows found in a table. If there are none, then do something.

SELECT COUNT (*) as count FROM AT_vbc_content_status

However, I keep getting this error...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) as count FROM [name of my table] WHERE member_id= '16'' at line 1

Where am I going wrong?



Solution 1:[1]

You have to remove the space between COUNT and (

COUNT(*)

Solution 2:[2]

Remove the space between COUNT and the parenthesis like this: COUNT(*)

See the MySQL documentation at the link below for explanation

http://dev.mysql.com/doc/refman/5.1/en/function-resolution.html

Solution 3:[3]

The MySql function is COUNT(field_name) and there must not be any space between COUNT and (*), So Remove the extra space between COUNT and (*)

$content_status_sql = "SELECT COUNT(*) as count FROM AT_vbc_content_status WHERE member_id= '".$_SESSION['member_id']."'";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M. Abbas
Solution 2 Mike Brant
Solution 3 Rajan Rawal