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 > How to make selection on a temporary created field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-10, 02:35
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
How to make selection on a temporary created field

Hi all,

I have an SQL query as follows:

Code:
Select bilgiler.*,(year(islemtarihi)-year(dogumtarihi)) as age from bilgiler where age between 1 and 25
MySQL does not accept the query. I need to create the field "yas" dynamically (field actually does not exist) and filter the people whose age is between 1 and 25.

Is there a way to do this?

Thanks
telmessos
Reply With Quote
  #2 (permalink)  
Old 04-13-10, 03:53
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Hi Telmessos,

You cannot include the alias name in the where clause. This should be written

select bilgiler.*, (year(islemtarihi)-year(dogumtarihi)) as age
from bilgiler
where (year(islemtarihi)-year(dogumtarihi)) between 0 and 25;
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 04-13-10, 04:00
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
Hi,

I'll try your query. Thanks for your time and help.

telmessos
Reply With Quote
  #4 (permalink)  
Old 04-13-10, 05:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT *
  FROM ( SELECT bilgiler.*
              , year(islemtarihi)-year(dogumtarihi) AS age 
           FROM bilgiler ) AS d
 WHERE age BETWEEN 1 AND 25
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-13-10, 05:35
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
I think thats another option. thanks to both of you.
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