This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Select statement error  RSS feed

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
am trying to select information from a few tables, and because some of the tables have overlapping fieldnames e.g. name etc, I am trying to reference them in my sql statment like this...
sqlString = "select myTable1.name, myTable2.name from myTable1, myTable2 where .... and so on and so on
this unfortunately does not work and I am told that 'column not found'
My question is can fields be referenced by their table name?
If not, how can specific tables be referenced in a similar way if they have different schemas?
By the way my connection is with the JDBC DBC bridge.... could the bridge be my problem.

Thanks in advance
Chris
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anything wrong with your partial SQL statement. Make sure your column is really "name" and not "Name" or "NAME". Column names are case sensitive. Also, try quering a sinle table and see if you get the same error message. If all this failes, show us your complete SQL statement followed by the complete error message. Sometimes those error messages aren't for the reasons you think.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which databases have case-sensitive column names? Neither Oracle nor MySQL do...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ron Newman:
Which databases have case-sensitive column names? Neither Oracle nor MySQL do...


MS SQL does.
 
author & internet detective
Sheriff
Posts: 38564
654
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You left out the table names. It should be:
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to rename the tables in a SELECT statement.
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Jeanne , I did include my tables after the 'from'...
I tried the select from a single statement like,
select table1.column1 from table1 where column2 = 'somevalue'

and got the same error, but the following works
select column1 from table1 where column2 = 'somevalue'

suggestions?
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U have to have consistent aliasing of the column names.
In you where clause u should prefix the column with the 'tablename.'
in the last instance where u had success, there were no aliases used, and by default all the columns were 'bound' to the table in the FROM part of the sql statement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!