You are here: Re: MySQL -- query that displays rows that can't be joined « PHP SQL « IT news, forums, messages
Re: MySQL -- query that displays rows that can't be joined

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация