Well, that's pretty much the specs of SQL: You get one row of output for each row in the table meeting the Where and Having criteria. If there are no such rows, then you get zero rows of output. What if your table has two rows? Are you expecting to get two rows of output or just one? Without knowing what you're really trying to accomplish it's hard to say much more, but I don't see how your question really makes sense: Like, "I want a list of all customers in New Hampshire, but if I have no customers in New Hampshire, tell me that there was one anyway."? If the question you're trying to ask is something more like, "Are there any ..." then perhaps you could write something like:

select if (count(*)>0,"a","b") as test from table where column='string';

Thomas Svenson writes:

Hi list,

I'm new here so I don't know if this has been discussed earlier.

I have a problem with the following:
SELECT IF(column = 'string', 'a', 'b') AS test FROM table;


It works just fine if the table is populated. However, if the table is empty
(which this one very well can be from time to time) I get no return value at
all.


Is there any way I can get MySQL to return "test = b" if the table is empty?

/T


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to