Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE TABLE Orders (ID INT); INSERT INTO Orders VALUES (1), (2), (3), (4), (5); CREATE TABLE OrdersProducts (ID INT IDENTITY(1, 1), OrderID INT, Code INT); INSERT INTO OrdersProducts (OrderID, Code ) VALUES (1, 100), (2, 200), (3, 300), (4, 400), (5, 500), (1, 110), (2, 220), (3, 330), (4, 440), (5, 550); WITH Last3Orders AS ( SELECT TOP(3) Id FROM Orders O ORDER BY Id DESC ) SELECT * FROM Last3Orders JOIN OrdersProducts ON Last3Orders.Id = OrdersProducts.OrderID ORDER BY OrderID DESC;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear