boneXXX Posted October 13, 2007 Share Posted October 13, 2007 Hi , I need a help to check 2 tables if the common column is same then I want to get the data. Such as; I have a Participant table: Number, Firstname, Surname and there is a Result table: Number, Min, Sec I want to get values Min and Sec if Numbers are equal in both table. $result = mysql_query("select Number,Number from Participant2,Result2 WHERE Participant2.Number =Result2.Number"); I get error with these query. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 13, 2007 Share Posted October 13, 2007 select p.Number, r.Number from participant2 p inner join Result2 r WHERE p.Number = r.Number; Quote Link to comment Share on other sites More sharing options...
boneXXX Posted October 14, 2007 Author Share Posted October 14, 2007 Thanks for the reply. I did it like this: SELECT Participant2.Number,Participant2.Number,Participant2.Firstname, Participant2.Surname, Result2.Min, Result2.Sec, Result2.Distance, Result2.Class FROM Participant2,Result2 WHERE Participant2.Number=Result2.Number; Quote Link to comment Share on other sites More sharing options...
seandon01 Posted October 14, 2007 Share Posted October 14, 2007 n~ link=topic=163309.msg716017#msg716017 date=1192293624] select p.Number, r.Number from participant2 p inner join Result2 r WHERE p.Number = r.Number; ~n[EO]n~, can you explain this please.. I often run into trouble when relating two tables together and returning data.. Thanks in advance Quote Link to comment Share on other sites More sharing options...
teng84 Posted October 14, 2007 Share Posted October 14, 2007 you cant call field name as it is when this field is present on the other table that will cause ambiguous error putting the tablename before your field will solve this issue eg.. tablename.field or use alias like the sample given to you r.field Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.