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/29/05 00:58

> This query works fine as is, but I can't seem to use the generated
> field in a WHERE clause at the end. Say you have a much larger table
> like the one mentioned above, and you want to add a "WHERE username =
> '(user no longer exists)' OR username = 'myusername'" to the end.

Refer to the original column name, not the aliased name. If it helps,
make the aliased name obviously different from the original...

SELECT
CASE ISNULL(username)
WHEN 1 THEN "(user no longer exists)"
ELSE username
END AS "username_x",
total_sales
FROM sales
LEFT OUTER JOIN users ON sales.userid = users.userid
WHERE ISNULL(username) OR username = "myusername"

---
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

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