Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How can I use a column alias in a where clause?

How can I use a column alias in a where clause?

Scheduled Pinned Locked Moved Database
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dobromir Dimitrov
    wrote on last edited by
    #1

    Hello, I'd like some help on the following problem - I need to use an alias as a condition in the where clause: select field1, field2, field3, field1*field2-field3 as some_alias from table1 where some_alias between 10 and 20 Using an alias like that returns the following error: Invalid column name 'some_alias'. Could anyone propose a solution?

    S 1 Reply Last reply
    0
    • D Dobromir Dimitrov

      Hello, I'd like some help on the following problem - I need to use an alias as a condition in the where clause: select field1, field2, field3, field1*field2-field3 as some_alias from table1 where some_alias between 10 and 20 Using an alias like that returns the following error: Invalid column name 'some_alias'. Could anyone propose a solution?

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Hi Dobromir, You can use the alias definition in the where clause. Here is your query modified:

      select field1,
      field2,
      field3,
      field1*field2-field3 as some_alias
      from table1
      where (field1*field2-field3) between 10 and 20

      Regards, Mehroz

      D 1 Reply Last reply
      0
      • S Syed Mehroz Alam

        Hi Dobromir, You can use the alias definition in the where clause. Here is your query modified:

        select field1,
        field2,
        field3,
        field1*field2-field3 as some_alias
        from table1
        where (field1*field2-field3) between 10 and 20

        Regards, Mehroz

        D Offline
        D Offline
        Dobromir Dimitrov
        wrote on last edited by
        #3

        thank you for your answer, but is'n this going to cause a recalculation of the value of the alias?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups