CONTACT() AS something - something in WHERE clause

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

CONTACT() AS something - something in WHERE clause

Post by anjanesh »

Any way to get this work in MySQL 4.0.x?

Code: Select all

SELECT *,
CONCAT(contact.FirstName,contact.LastName,contact.Phone) AS Uniq
FROM `contacts` contact
WHERE Uniq = 'MyFirstnameMyLastname101-10101-101'
Thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You should repeat the complete statement...

Code: Select all

SELECT *, CONCAT(contact.FirstName,contact.LastName,contact.Phone) AS Uniq
FROM `contacts` contact
WHERE CONCAT(contact.FirstName,contact.LastName,contact.Phone) = 'MyFirstnameMyLastname101-10101-101'

SQL queries are processed as following:
1 - from
2 - where
3 - group by
4 - having
5 - select
6 - order by

By the time the where clause is processed, it doesn't know about aliases defined in the where clause...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Ah...Thanks
Post Reply