Skip to content
Advertisement

SQLite book shop: Last students and all books they ordered

forum. I’m trying to run SQL for my local book-shop. The problem is to show last N students and all books they ordered.

My try:

Is it okay code? Syntax check only shows mistake in a row 8, which I don’t get. Thank you in advance

Advertisement

Answer

You can join books to orders and filter the results for the last N students:

The CTE returns the last 3 students (by date and not by id) who ordered a book.

See the demo.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement