Jump to content

Checking two tables


boneXXX

Recommended Posts

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.