Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    26

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

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Jan 2010
    Posts
    26
    Hi,

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

    telmessos

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT *
      FROM ( SELECT bilgiler.*
                  , year(islemtarihi)-year(dogumtarihi) AS age 
               FROM bilgiler ) AS d
     WHERE age BETWEEN 1 AND 25
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2010
    Posts
    26
    I think thats another option. thanks to both of you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •