how to left join works in mysql

Recommended Answers

All 4 Replies

-family table
Position    Age
Dad         41
Mom         45
Daughter    17

-food table
Meal    Position
Steak   Dad
Salad   Mom
Spinach Soup    
Tacos   Dad
left join codes here.....

// Make a MySQL Connection
// Construct our join query
$query = "SELECT family.Position, food.Meal ".
 "FROM family LEFT 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 "<br />";
heres the output....

Dad - Steak
Dad - Tacos
Mom - Salad
Daughter -
Dog -
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.