• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQL error:Invalid identifier

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am sql rookie and I would appreciate very much some assistance on this rather basic issue.

select comp_table.* from (select column_1,avg(column_2) as "avg" from table_1, group by column_1) comp_table---> returns correct records with 2 columns named : column_1, avg;

But if I change to :

select comp_table.avg from (select column_1,avg(column_2) as "avg" from table_1, group by column_1) comp_table---> returns Error: Invalid identifier "avg"

The thing is I only need to select the avg column; So I cannot do select comp_table.*. Can you guys please help?
Also, if you could kindly provide some tuning tips for the query...that would be awesome.

Thank you.


 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roy,
You just need to not define your column as a literal. (No need for the quotes around the column name)
Use


If you just need the avg column with out the identifier you do not need the inner query

Also it can be best to try to stay away from what may be reserved words in any language like avg for column heading. Who knows if someone is going to import the results into a spreadsheet or such like.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch , Byron Mabbett
 
Victor Ramen
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. It solved the problem.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic