diff --git a/chapter1.html b/chapter1.html index f611c67..c42fd6a 100644 --- a/chapter1.html +++ b/chapter1.html @@ -21,6 +21,8 @@
To perform a SQL query to a database, enter the command in the text field and click on Execute Command. As an alternative to Sqlitebrowser you can use Sqliteman which is a good alternative especially for Debian and Ubuntu Linux users. Please refer to the installation guide for details.
+ +As the focus of this tutorial lies on the retrieval of data from an existing database rather than creating new databases, a file databaseOTS.sqlite is provided which contains all the data required later on in the course. Download this file to some location on your computer. Then you can open it in DB Browser for SQLite by clicking on open database.
diff --git a/chapter2.html b/chapter2.html index d35db30..deb23d9 100644 --- a/chapter2.html +++ b/chapter2.html @@ -17,14 +17,13 @@We want to see what is in the table person:
select * from person;
This is too much information as we are only interested in the name:
select name from person;
In general:
select col1, col2, ... from tablename;-
We can get the number of lines of results by using the count command. To get the number of entries in the person table we use
+Note that select *
selects all columns of the respective table. We can get the number of lines of results by using the count command. To get the number of entries in the person table we use
select count(*) from person;
Results might contain duplicates (they form a multi-set). We can get only the distinct results by
select distinct col1,col2, ... from tablename;@@ -37,12 +36,8 @@
select name, residence from person where age > 30;
For the different type of data, different constrains make sense. For all kind of data, we can check for equal =
and not equal !=
. For numbers, one can also compare for larger >
, larger or equal >=
, smaller <
, smaller or equal <=
.
For text, we use For text, we use For text, we use 3.) Get all people whose names contains "oh". In SQLite the Constraints can be combined by the logical operator 6.) Find all people whose first name is Carlos and who are older than 20 years. There is another table which is called 7.) Find out, how many contracts there are and how many accounts are active. 7.) Find out, how many contracts there. With a second query find out how many of them are and how many accounts are active. Usually, it is necessary to get information which is spread over more than one table. For example, you may want to know the names of the people who have an active phone contract. As we did not want to write the complete table name, we have defined and abbreviation in the 9.) Find all names who have an active phone contract. 9.) Find all names and ages of persons who have an active phone contract. 10.) Find all names and phone numbers of people who are older than 30. If you have no more question concerning basics SQL queries, you can procede to the next chapter and solve the theft of the Mona Lisa.like
, to find entries where the text value in a column contains a string, where you can use the %
as a wild-card for unknown parts of a word. E.g. if you search for '%an%'
, the following words would fit: Banana, fantasy. Note that in SQLite, the like
operator is case insensitive by default.
+like
, to find entries where the text value in a column contains a string, where you can use the %
as a wild-card for unknown parts of a word. E.g. if you search for '%an%'
, the following words would fit: Banana, fantasy. Note that in SQLite, the like
operator is case insensitive by default.
-=======
-like
, to find entries where the text value in a column contains a string. The string should be surrounded by single quotes '
, and you can use the %
as a wild-card for unknown parts of a word. E.g. if you search for '%an%'
, the following words would fit: Banana, fantasy, but not Anna, since this is a Capital A.>
,<
,=
operators for dates, do an lexicographical comparison, not a numeric one. This means that if there is an inconsistent representation of dates, the comparison might fail even though the two values represent the same dates. E.g. if once the format "2014-10-23"
and once the format "2014/10/16"
is used. Note that here double quotes "
are used instead of single quotes '
.flight
containg flight data. The column with the dates is called date
.
@@ -59,7 +54,7 @@ Constraints
and
and the operator or
.phone_contract
. The column containing the status (active, non-active) is called status
.Results from more than one table
Results from more than one table
select p.name, c.phone_number from person p, phone_contract c
where c.name = p.name;
from
clause (person p
).Sub-queries
@@ -91,7 +86,7 @@ Sub-queries