Link to home
Start Free TrialLog in
Avatar of pixegoo
pixegoo

asked on

INNER JOIN WITH SAME PRIMARY ID

I have 2 tables whit  this attributes
   TABLE A = person --> id | firstname  | lastname     |   jobtitle
   TABLE B = contact--> id | id_person  | description  | secondlastname
 
This is my query in mysql, operating correctly

$query_services = mysql_query("SELECT A.*,B.* FROM person A LEFT JOIN contact B ON A.id=B.person_id WHERE $con ORDER BY A.id ");

while ($row_services = mysql_fetch_array($query_services)) {
$id=$row_services['id'];
$nam=$row_services['firstname'];
$last=$row_services['lastname'];
$seclast=$row_services['secondlastname'];

MY PROBLEM IS
I WANT TO GET THE 'id' = $id OF TABLE 'person'
BUT, I get 'id' the table 'contact'. (I do not want that record)

should I do?
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of magarity
magarity

Just itemize the fields you want instead of using A.* and B.*:  A.ID, A.firstname ... B.description, B.secondlastname
You do not need to SELECT fields in order to use them in JOIN or WHERE clauses. This will make sure you only get the ID from table A.
You can also specify an alias for the field.  

Select A.ID as PERSON_ID, B.ID as CONTACT_ID...

Open in new window