Here we introduce basic data manipulation statements: SELECT, INSERT, UPDATE, DELETE and how to restrict results using WHERE and LIMIT. Also how to order results using custom fields.
ТАБЛИЦА, ОТ КОЯТО ЧЕТЕМ name author Lord of the rings J. R. R. Tolkien It Stephen King Firestarter Stephen King Cell Stephen King Going postal Terry Pratchet Running man Stephen King SELECT book.name, author.name AS "author" FROM book INNER JOIN author USING (author_id);
J. R. R. Tolkien 1 Paulo Coehlo 0 SELECT author.name, COUNT(book.book_id) AS "books" FROM author LEFT JOIN book USING (author_id) GROUP BY author.author_id;
author_id genre 1 Lord of the rings 3 fantasy 2 It 1 horror 3 Firestarter 1 horror 4 Cell 1 horror 5 Going postal 2 fantasy 6 Foundation NULL Sci Fi SELECT * FROM book;
1 Lord of the rings 3 fantasy 5 Going postal 2 fantasy 2 It 1 horror 3 Firestarter 1 horror 4 Cell 1 horror 6 Foundation NULL Sci Fi 7 Running man 1 Sci Fi SELECT * FROM book ORDER BY genre;
author_id genre 5 Going postal 2 fantasy 1 Lord of the rings 3 fantasy 4 Cell 1 horror 3 Firestarter 1 horror 2 It 1 horror 6 Foundation NULL Sci Fi 7 Running man 1 Sci Fi SELECT * FROM book ORDER BY genre, name;
rings 3 fantasy 2 It 1 horror 3 Firestarter 1 horror 4 Cell 1 horror 5 Going postal 2 fantasy 6 Foundation NULL Sci Fi 7 Running man 1 Sci Fi SELECT * FROM book;