tags:

views:

24

answers:

2

Hi,

I've got a mySQL query that produces an empty set. For example,

SELECT id 
FROM `my_table` 
WHERE type = 'old'
AND neighborhoods = 'Newport'

produces an empty set. In the event that the query produces an empty set is it possible to have it return:

id
---
0

Thank you.

-Laxmidi

A: 

You can add in a COUNT part of the query

SELECT id, COUNT(id) as Total FROM my_table WHERE type = 'old' AND neighborhoods = 'Newport'

And that will return at least one record with Total=0

jerebear
I left id, and COUNT() as the parameters so you will either get a result of "0" or you will get the record set.
jerebear
jerebear, Thanks so much! It works great.
Laxmidi
A: 

Yes,

SELECT COUNT(id) 
FROM `my_table` 
WHERE type = 'old'
AND neighborhoods = 'Newport'

Will always returns a result set.

Multiplexer