How to list records for a query and to display “no records” when no rows returned using a single query?
Currently I am using a COUNT(*) query or using mysql_num_rows() function; then another query in different result set to list data. Can you tell me if it is possible to accomplish the same with a single query?
Important: I assume that the OP uses PHP as (s)he mentions
mysql_num_rows. And I hope (s)he will tell me if I am wrong.It is your job in PHP to check whether the result is an empty set or not. I don’t understand why you have to do another query. Maybe you have to clarify your question.
Here a more complete example:
Reference:
mysql_num_rows,mysql_fetch_arrayEven if you don’t use PHP, the approach is the same in other languages and there should be similar functions available.