...
And if we populate it with some data
first name | last name | destination city | destination country | reason for visit | number of visits |
---|---|---|---|---|---|
Sel | RTR | Buzios | Brasil | Sun | 2 |
Sel | RTR | Jo/burg | South Africa | Work, Sun | 4 |
Sel | RTR | Nepal | Mountains | 2 | |
Sel | RTR | Rio De Janeiro | Brasil | Lifestyle, Sun | 2 |
Sel | RTR | empumalanga | South Africa | Safari | 2 |
Sel | RTR | Flogaman | Jamaica | Family, Sun, Lifestyle | 10 |
...
In our example above, we can easily link the two tables together because there is only one traveller. But what if we were to increase the number of travellers and destinations to the following sets
Traveller Table
first name | last name |
---|---|
Sel | RTR |
Sam | Wright |
Carol | Anne |
Destination Table
destination city | destination country | reason for visit | number of visits |
---|---|---|---|
Buzios | Brasil | Sun | 2 |
Jo/burg | South Africa | Work, Sun | 4 |
Tokyo | Japan | Manga comics | 2 |
Nepal | Mountains | 2 | |
Mauritius | India | Chilling in the sun | 3 |
Rio De Janeiro | Brasil | Lifestyle, Sun | 2 |
Bridgetown | Barbados | Sun | 3 |
Puerto Banús | Spain | Lifestyle | 5 |
Empumalanga | South Africa | Safari | 2 |
Flogaman | Jamaica | Family, Sun, Lifestyle | 10 |
...
And populated with the updated IDs
Traveller Table
traveller id | first name | last name |
---|---|---|
1 | Sel | RTR |
2 | Sam | Wright |
3 | Carol | Anne |
Destination Table
destination id | destination city | destination country | reason for visit | number of visits |
---|---|---|---|---|
1 | Buzios | Brasil | Sun | 2 |
2 | Jo/burg | South Africa | Work, Sun | 4 |
3 | Tokyo | Japan | Manga comics | 2 |
4 | Nepal | Mountains | 2 | |
5 | Port Luis | Mauritius | Chilling in the sun | 3 |
6 | Rio De Janeiro | Brasil | Lifestyle, Sun | 2 |
7 | Bridgetown | Barbados | Sun | 3 |
8 | Puerto Banús | Spain | Lifestyle | 5 |
9 | Empumalanga | South Africa | Safari | 2 |
10 | Flogaman | Jamaica | Family, Sun, Lifestyle | 10 |
...
The most general syntax is - insert a value into each and every column
|
...
The most common syntax is - insert a value into selected columns
|
...
The usual syntax when a field has an auto increment constraint - insert to selected fields
|
...
Its most basic form is the following - this will read all data from all columns
|
...
You can restrict the columns returned using
|
...
We can restrict the amount of data returned using this SELECT ... WHERE form
|
...
A SQL join is an instruction to combine data from two sets of data (i.e. two tables). So in our example above we can bring the two tables back together as a single result set using the following query
|
Unfortunately when you run this query it will duplicate the traveller_id because the select * selects all columns from both tables. Let's narrow this by altering the query
|
...