In article <[EMAIL PROTECTED]>, John Mistler <[EMAIL PROTECTED]> writes:
> Good idea. liang le's answer almost got it, but I couldn't make it work > with string values quite right. Here is my situation: > I am issuing a series of queries all-in-one like "SELECT nameColumn, > otherColumn FROM theDatabase WHERE rowID = 1;SELECT nameColumn, otherColumn > FROM theDatabase WHERE rowID = 2;SELECT nameColumn, otherColumn FROM > theDatabase WHERE rowID = 3;" > expecting a return of > aName otherItem > aName otherItem > aName otherItem > but if one of those rowIDs does not exist, then I get > aName otherItem > aName otherItem > and my app has no value for the non-existing row. I would like for the > query to return an indication that the row did not exist, like: > aName otherItem > 0 or '' or 'NULL' (no nameColumn entries will ever = 0, or '', or NULL) > aName otherItem > Does that make more sense, and if so, is there a solution? This sounds like a broken DB design. You should have another table listing all possible rowIDs; something like that: CREATE TABLE myRows ( rowID INT NOT NULL, nameColumn VARCHAR(255) NOT NULL, PRIMARY KEY (rowID) ); INSERT INTO myRows (1, 'row #1'); INSERT INTO myRows (2, 'row #2'); INSERT INTO myRows (3, 'row #3'); Then you can do the following: SELECT t1.nameColumn, coalesce(t2.otherColumn, '') FROM myRows t1 LEFT JOIN yourTable t2 ON t2.rowID = t1.rowID -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]