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_s ervices)) {
$id=$row_services['id'];
$nam=$row_services['firstn ame'];
$last=$row_services['lastn ame'];
$seclast=$row_services['se condlastna me'];
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?
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_s
$id=$row_services['id'];
$nam=$row_services['firstn
$last=$row_services['lastn
$seclast=$row_services['se
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also specify an alias for the field.
Select A.ID as PERSON_ID, B.ID as CONTACT_ID...
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.