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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

odd Joining problem

Status
Not open for further replies.

simanek

Programmer
Jan 19, 2001
137
US
Hi all,

Does anyone have any idea why the following statment succeed (BMMT is the table name):


SELECT * FROM BMMT WHERE make='optic' and Classification='super_special';

and this one won't even though inherently, there is no difference in the WHERE statment:

SELECT * FROM BMMT INNER JOIN hTypenumL on BMMT.typenum=hTypenumL.typenum WHERE BMMT.make='optic' and BMMT.Classification='super_special';

Any help is very much appreciated. Thanks.

Mike
~~~~
simanek@uiuc.edu
"It's a Swingline!"
~~~~
 
I assume hTypenumL is another table?
Are you getting an error or is it just not returning the rows it should? If it's an error, what is it?
 
Problem:
You cannot use * the SELECT portion of table join query. You must use tablename.*. Since there are multiple column with the same name the RDBMS doesn't know which one you want. Try this:
Code:
SELECT BMMT.*,hTypenumL.* FROM BMMT INNER JOIN hTypenumL on BMMT.typenum=hTypenumL.typenum WHERE BMMT.make='optic' and BMMT.Classification='super_special';

Note:
You may need to use an OUTER JOIN. If hTypenumL has no values for the records you are requesting than you may not get the results you want.

Wushutwist
 
That depends on the database. I use SQL Server and it has no problem with SELECT * from joined tables with the same column names (not that that's a good way to code).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top