forked from Ifah/PHP-Tutorials-thenewboston
-
Notifications
You must be signed in to change notification settings - Fork 0
/
127 - 129 LEFT JOIN RIGHT JOIN JOIN.php
36 lines (27 loc) · 1.14 KB
/
127 - 129 LEFT JOIN RIGHT JOIN JOIN.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
// (left side) ON (right side)
//LEFT JOIN - do display data on the left even if data doesnt exist on the right
//"SELECT people.name, pets.pet FROM people LEFT JOIN pets ON people.id=pets.people_id";
//"SELECT people.name, pets.pet FROM people LEFT JOIN pets ON people.id=pets.people_id LIMIT 0, 30";
//OUT PUT =
// name pet
// Alex Cat
// Alex Fish
// Dale NULL
//RIGHT JOIN - to display data on the right hand side even if the corresponding value on left hand side doesnt exist. for example Dog exists while Dale does not exists
//"SELECT people.name, pets.pet FROM people RIGHT JOIN pets ON people.id=pets.people_id";
//"SELECT people.name, pets.pet FROM people RIGHT JOIN pets ON people.id=pets.people_id LIMIT 0, 30";
//OUT PUT =
// name pet
// Alex Cat
// Alex Fish
// NULL Dog
//JOIN - values that exists on both tables, left hand side and right hand side
//"SELECT people.name, pets.pet FROM people JOIN pets ON people.id=pets.people_id";
//"SELECT people.name, pets.pet FROM people JOIN pets ON people.id=pets.people_id LIMIT 0, 30";
//OUT PUT =
// name pet
// Alex Cat
// Alex Fish
//
?>