If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Checking for CONCAT() in WHERE clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-06, 06:55
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Checking for CONCAT() in WHERE clause

Any way to get this working ?
Code:
SELECT *,
CONCAT(`field1`, `field2`,`field3`,`field4`,`field5`) AS Uniq
FROM `table1` WHERE Uniq = 'somevalue'
Neither does this work too.
Code:
SELECT *,
CONCAT(`field1`, `field2`,`field3`,`field4`,`field5`) AS tbl1.Uniq
FROM `table1` tbl1 WHERE tbl1.Uniq = 'somevalue'
Reply With Quote
  #2 (permalink)  
Old 01-07-06, 11:49
yellowmarker yellowmarker is offline
Registered User
 
Join Date: Jul 2004
Location: Dundee, Scotland
Posts: 107
It is not possible to use a field alias in the WHERE clause. Your solution would be either to check the value each field in the WHERE clause, or possibly to use an IF condition in your SELECT clause. If neither of these alternatives are appropriate you might decide to make use of a temporary table.

see http://dev.mysql.com/doc/refman/5.0/en/select.html

"The alias is used as the expression's column name and can be used in GROUP BY, ORDER BY, or HAVING clauses."

"It is not allowable to use a column alias in a WHERE clause, because the column value might not yet be determined when the WHERE clause is executed."

Last edited by yellowmarker; 01-07-06 at 11:51.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On