Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in creating this query 1

Status
Not open for further replies.

royboy75

Programmer
Feb 13, 2007
114
GB
Hello,

Suppose I have two tables: A and B.
I would like to create a SELECT query that gives me two fields from table A and the rest of the fields from table B without specifying the columns names of table B?
The reason I need this is this: In table A I have the user's first and last name and in table B I have the rest of it's data. The thing is that each time table B will be a different table with different columns in it, that's why I want to avoid specifying the names. In table A it will always be the same two fields. Now, I cannot do simply SELECT * because table A and B have one field in common which will cause ambiguously.
I am building this query dynamically in my Java code and concatenate table B name there, depending on the user's choice.

 
Not tested, but aliases might be what you're looking for,

select a.column1, a.column2, b.*
from tablea a, tableb, b
where a.joincol = b.joincol

I want to be good, is that not enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top