|
Posted by Steve on 11/28/05 18:12
> Hello, I'm using PHP 4 and MySQL 4. Is it possible to write a query
> that joins two tables, but if one value cannot be matched, the row
> would not be excluded, but a value could be substituted. For example,
> How could I write a single query tnat would give the following results?
> USERNAME TOTAL_SALES
> ---------------------------------------------------------------
> myusername 125.00
> (user no longer exists) 55.00
SELECT
CASE ISNULL(username)
WHEN 1 THEN "(user no longer exists)"
ELSE username
END AS "username",
total_sales
FROM sales
LEFT OUTER JOIN users ON sales.userid = users.userid
---
Steve
Navigation:
[Reply to this message]
|