简体   繁体   中英

How to compare two rows from different tables and show the table values if the rows match?

I have two different tables. One is person and the other one is Cardholder . Both of these tables have one row with the similar name and same value and its called personId . What I am trying to do is compare the row personId on the person table to personId on the Cardholder table and print only rows that match the value of personId on both tables. How would I write in PHP to do such task? I tried few things but failed to do what I intend.

The sql query would look something like this :

SELECT P.* FROM person P INNER JOIN Cardholder C ON C.personId=P.personId

this would only select the fields from the table person that has a match on personId in the Cardholder table.

You will need code like this one

MySQL Code: -

("SELECT Cardholder.personId, person.personId FROM Cardholder INNER JOIN person ON Cardholder.personId = person.personId");

PHP Code: -

if (count($SQLstatment) > 0) {Exist} else {Not}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM