Browse by category

All books

Best sellers

See all
Cover of 1984

★★★★★ (2)

1984 George Orwell

Penguin Books

₺185.00
Cover of Dune

★★★★☆ (1)

Dune Frank Herbert

Penguin Books

₺340.00
Cover of The Hobbit

★★★★★ (1)

The Hobbit J.R.R. Tolkien

HarperCollins

₺280.00

New arrivals

See all
New Cover of Çalıkuşu

No reviews yet

Çalıkuşu Reşat Nuri Güntekin

İnkılâp Kitabevi

Only 8 left
₺210.00
New Cover of İnce Memed

★★★★★ (1)

İnce Memed Yaşar Kemal

Yapı Kredi Yayınları

₺345.00

All books

17 books listed, title A-Z
Cover of 1984

★★★★★ (2)

1984 George Orwell

Penguin Books

₺185.00
Cover of Animal Farm

No reviews yet

Animal Farm George Orwell

Penguin Books

₺120.00
New Cover of Çalıkuşu

No reviews yet

Çalıkuşu Reşat Nuri Güntekin

İnkılâp Kitabevi

Only 8 left
₺210.00
Cover of Dune

★★★★☆ (1)

Dune Frank Herbert

Penguin Books

₺340.00
Cover of Good Omens

★★★★☆ (1)

Good Omens Terry Pratchett, Neil Gaiman

HarperCollins

₺295.00
New Cover of İnce Memed

★★★★★ (1)

İnce Memed Yaşar Kemal

Yapı Kredi Yayınları

₺345.00
Cover of Learning SQL

★★★★☆ (1)

Learning SQL Alan Beaulieu

O'Reilly Media

Only 10 left
₺1180.00
Cover of The Hobbit

★★★★★ (1)

The Hobbit J.R.R. Tolkien

HarperCollins

₺280.00
Cover of Tutunamayanlar

★★★★☆ (1)

Tutunamayanlar Oğuz Atay

İletişim Yayınları

₺390.00
SQL behind this page 5 statements

This page was built with 5 statements

  1. SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Builds: the book cards of the list (title, authors, publisher, price, stock) and the number of books listed.

    %s values, in order: '%%''''%%'

    Show on the page
    Picture

    The page as it is now. Red: what this statement builds.

    Step by step
    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 1 of 9

    SELECT

    Chooses the columns (or computed values) that the result shows. Here STRING_AGG joins the texts of several rows into one text.

    Back
    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 2 of 9

    FROM

    The table the rows come from.

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 3 of 9

    JOIN

    Adds the matching row of another table; the ON part says which columns must be equal.

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 4 of 9

    JOIN

    Adds the matching row of another table; the ON part says which columns must be equal.

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 5 of 9

    LEFT JOIN

    Like JOIN, but a row is kept even when the other table has no match (then its columns are empty).

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 6 of 9

    LEFT JOIN

    Like JOIN, but a row is kept even when the other table has no match (then its columns are empty).

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 7 of 9

    WHERE

    Keeps only the rows for which the condition is true; AND and OR combine several conditions. It holds a subquery in brackets: the subquery runs first and gives its result to the outer query. Each %s stands for a value (for example one typed in a form) that is sent separately from the SQL text, which is why text typed in a form cannot change the query.

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 8 of 9

    GROUP BY

    Puts the rows with the same values into one group, so COUNT, SUM or AVG give one result per group.

    SELECT b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
           b.category_id, b.cover_image, c.name AS category, p.name AS publisher,
           STRING_AGG(a.first_name || ' ' || a.last_name, ', ') AS authors
    FROM book b
    JOIN category c          ON c.category_id  = b.category_id
    JOIN publisher p         ON p.publisher_id = b.publisher_id
    LEFT JOIN book_author ba ON ba.book_id     = b.book_id
    LEFT JOIN author a       ON a.author_id    = ba.author_id
    WHERE (b.title ILIKE %s
           OR b.isbn = %s
           OR b.book_id IN (SELECT ba2.book_id
                            FROM book_author ba2
                            JOIN author a2 ON a2.author_id = ba2.author_id
                            WHERE a2.first_name || ' ' || a2.last_name ILIKE %s))
    GROUP BY b.book_id, b.title, b.price, b.stock_quantity, b.publication_year,
             b.category_id, b.cover_image, c.name, p.name
    ORDER BY b.title

    Step 9 of 9

    ORDER BY

    Sorts the result by these columns, from the smallest to the largest (A to Z) unless DESC is written.

    Back to this SQL statement
  2. SELECT book_id, ROUND(AVG(rating), 1) AS avg_rating, COUNT(*) AS review_count
    FROM review
    GROUP BY book_id

    Builds: the stars and review counts on the cards.

    Show on the page
    Picture

    The page as it is now. Red: what this statement builds.

    Step by step
    SELECT book_id, ROUND(AVG(rating), 1) AS avg_rating, COUNT(*) AS review_count
    FROM review
    GROUP BY book_id

    Step 1 of 3

    SELECT

    Chooses the columns (or computed values) that the result shows. Here COUNT counts rows, AVG gives the average value.

    Back
    SELECT book_id, ROUND(AVG(rating), 1) AS avg_rating, COUNT(*) AS review_count
    FROM review
    GROUP BY book_id

    Step 2 of 3

    FROM

    The table the rows come from.

    SELECT book_id, ROUND(AVG(rating), 1) AS avg_rating, COUNT(*) AS review_count
    FROM review
    GROUP BY book_id

    Step 3 of 3

    GROUP BY

    Puts the rows with the same values into one group, so COUNT, SUM or AVG give one result per group.

    Back to this SQL statement
  3. SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Builds: the podium at the top and the Best sellers shelf: which books, in which order, and how many copies were ordered.

    Show on the page
    Picture

    The page as it is now. Red: what this statement builds.

    Step by step
    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 1 of 7

    SELECT

    Chooses the columns (or computed values) that the result shows. Here SUM adds the values up.

    Back
    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 2 of 7

    FROM

    The table the rows come from.

    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 3 of 7

    JOIN

    Adds the matching row of another table; the ON part says which columns must be equal.

    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 4 of 7

    WHERE

    Keeps only the rows for which the condition is true; AND and OR combine several conditions.

    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 5 of 7

    GROUP BY

    Puts the rows with the same values into one group, so COUNT, SUM or AVG give one result per group.

    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 6 of 7

    ORDER BY

    Sorts the result by these columns, from the smallest to the largest (A to Z) unless DESC is written.

    SELECT oi.book_id, SUM(oi.quantity) AS copies_sold
    FROM order_item oi
    JOIN orders o ON o.order_id = oi.order_id
    WHERE o.status != 'cancelled'
    GROUP BY oi.book_id
    ORDER BY copies_sold DESC, oi.book_id
    LIMIT 5

    Step 7 of 7

    LIMIT

    Keeps only the first rows of the result, at most this many.

    Back to this SQL statement
  4. SELECT book_id FROM book ORDER BY book_id DESC LIMIT 5

    Builds: the four books standing in the banner and the New arrivals shelf.

    Show on the page
    Picture

    The page as it is now. Red: what this statement builds.

    Step by step
    SELECT book_id FROM book ORDER BY book_id DESC LIMIT 5

    Step 1 of 4

    SELECT

    Chooses the columns (or computed values) that the result shows.

    Back
    SELECT book_id FROM book ORDER BY book_id DESC LIMIT 5

    Step 2 of 4

    FROM

    The table the rows come from.

    SELECT book_id FROM book ORDER BY book_id DESC LIMIT 5

    Step 3 of 4

    ORDER BY

    Sorts the result by these columns, from the smallest to the largest (A to Z) unless DESC is written.

    SELECT book_id FROM book ORDER BY book_id DESC LIMIT 5

    Step 4 of 4

    LIMIT

    Keeps only the first rows of the result, at most this many.

    Back to this SQL statement
  5. SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Builds: the category links: in the menu row and the footer, and on a book list the category band or the side list with the number of books.

    Show on the page
    Picture

    The page as it is now. Red: what this statement builds.

    Step by step
    SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Step 1 of 5

    SELECT

    Chooses the columns (or computed values) that the result shows. Here COUNT counts rows.

    Back
    SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Step 2 of 5

    FROM

    The table the rows come from.

    SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Step 3 of 5

    LEFT JOIN

    Like JOIN, but a row is kept even when the other table has no match (then its columns are empty).

    SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Step 4 of 5

    GROUP BY

    Puts the rows with the same values into one group, so COUNT, SUM or AVG give one result per group.

    SELECT c.category_id, c.name, COUNT(b.book_id) AS book_count
    FROM category c
    LEFT JOIN book b ON b.category_id = c.category_id
    GROUP BY c.category_id, c.name
    ORDER BY c.name

    Step 5 of 5

    ORDER BY

    Sorts the result by these columns, from the smallest to the largest (A to Z) unless DESC is written.

    Back to this SQL statement