This will be the most basic parts of SQL queries. Below is the database we will use, so go ahead and add this to your database.
I called the database "people" and it is filled with some made up swedish people.

Making a choice
In this first part we will go through choosing the right rows and columns, very basic, but still so important, read it carefully, there is a in many cases some new small details you can learn
We will start by the most basic, returning all posts:
Code: Select all
SELECT * FROM people;Now to something more advanced, we now only want to get the
first name and hometown.
Code: Select all
SELECT Firstname, Hometown FROM people;load on the SQL server. This would return:

For the next step we want to get all the people that live in Stockholm
Code: Select all
SELECT * FROM people WHERE Hometown = 'Stockholm';
If you want to get rows with a specific ID, or other number, you would not need the ' around it, that is just
for dates, strings, and so on.
Code: Select all
SELECT * FROM people WHERE ID = 1;Code: Select all
SELECT * FROM people WHERE Hometown = Stockholm;Code: Select all
SELECT * FROM people WHERE Hometown = "Malmö" OR Lastname = "Svensson";You can also use the AND to demand that both are true
Code: Select all
SELECT * FROM people WHERE Hometown = "Stockholm" AND Lastname = "Gustavsson";
