470,848 Members | 1,822 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

mysql question : CASE

I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am using
mySQL 4.1

Thanks in advance!
Jan 4 '06 #1
4 1153
On Wed, 04 Jan 2006 17:05:27 +0100, Geradeaus wrote:
I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am using
mySQL 4.1

Thanks in advance!


Is there a union in mysql 4.1?

Jan 4 '06 #2
You might want to try comp.databases.mysql for comprehensive answers.
(X-Post and Followup-To set)

Geradeaus wrote:
I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am using
mySQL 4.1


....
WHERE adId in (1, 2)

not tested!

Jan 4 '06 #3
On Wed, 4 Jan 2006 17:05:27 +0100, "Geradeaus"
<ge*******************@hotmail.com> wrote:
I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am using
mySQL 4.1


Repeat the CASE in the WHERE clause.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 4 '06 #4

"Andy Hassall" <an**@andyh.co.uk> schreef in bericht
news:tk********************************@4ax.com...
On Wed, 4 Jan 2006 17:05:27 +0100, "Geradeaus"
<ge*******************@hotmail.com> wrote:
I have searched but have not yet found how I can resolve the following
problem :

SELECT adId,
CASE
WHEN adId =1 THEN cityId
WHEN adId =2 THEN regionId
END AS extraField
FROM ad
WHERE extraField <> 0

The problem is "extraField" cannot be used in the WHERE clause... I am
using
mySQL 4.1


Repeat the CASE in the WHERE clause.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool


thanks when I repeat it, it works :)
Jan 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gordon | last post: by
reply views Thread by Lenz Grimmer | last post: by
4 posts views Thread by Jeff S | last post: by
1 post views Thread by windandwaves | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.