#1 SQL

SQL (Structured Query Language ) is language created for querying from database.

Assume you have a database. You want to insert new stuff, update it, select some stuff or maybe delete it overtime.

Easy explained, the database consists of several tables, for example table of students:

idnamesurnamedate_of_birthhas_bicycle
1JohnSmith1995/05/15true
2Alex Hunnybun2004/01/19false
3Carol Gladden2005/10/13true

The first column is unique id of record in the table (it is not number of the row as we can delete second row and row with id 3 will be second then).

Let’s start with selection. The basic syntax is:

/* comment in sql */
/* basic syntax ended with ; */ SELECT columns FROM table;
/* examples */
/* 1 */ SELECT id FROM students;
/* 2 */ SELECT name, surname FROM students;
/* 3 */ SELECT id, name, surname, date_of_birth, has_bicycle FROM students;
/* 4 */ SELECT * FROM students;

The first query SELECT id FROM students will return whole column with ids. The last 2 queries are the same, * character means everything (every column). The result of query number 2 will be:

namesurname
JohnSmith
AlexHunnybun
CarolGladden

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *