The INNER JOIN keyword returns rows when there is at least one match in both tables.
family Table:
Position | Age |
Dad | 41 |
Mom | 35 |
Daughter | 17 |
Dog | 12 |
food Table:
Meal | Position |
Rice | Dad |
Dosa | Mom |
Idly | |
Egg | Dog |
The INNER JOIN keyword returns rows when there is at least one match in both tables. If there are rows in "family" that do not have matches in "food", those rows will NOT be listed.
<?php
/* Make a MySQL Connection */
$query = "SELECT family.Position, food.Meal FROM family INNER JOIN food ON
family.Position = food.Position";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['Position']. " - ". $row['Meal'];
echo "
";
}
?>
Output:-
Mom - Rice
Dad - Dosa
Dog - Egg
No comments:
Post a Comment