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 code ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, description TEXT, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Create the `code_like` table CREATE TABLE code_like ( id INT AUTO_INCREMENT PRIMARY KEY, code_id INT NOT NULL, user_id INT NOT NULL, liked_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (code_id) REFERENCES code(id) ON DELETE CASCADE ); INSERT INTO code (id, title, description, created_at) VALUES (1, 'Hello World', 'Prints Hello World', '2025-01-01 10:00:00'), (2, 'FizzBuzz', 'Classic FizzBuzz test', '2025-01-02 11:15:00'), (3, 'Recursive Factorial', 'Compute factorial n!', '2025-01-03 09:30:00'), (4, 'Sort Algorithm', 'Implements merge sort', '2025-01-04 14:45:00'), (5, 'Database Connection', 'PDO connection example', '2025-01-05 08:20:00'); INSERT INTO code_like (code_id, user_id, liked_at) VALUES (1, 101, '2025-02-01 12:00:00'), (1, 102, '2025-02-01 12:01:00'), (1, 103, '2025-02-01 12:02:00'), (2, 104, '2025-02-02 13:00:00'), (4, 105, '2025-02-03 14:00:00'), (4, 106, '2025-02-03 14:05:00'), (5, 107, '2025-02-04 15:00:00'); SELECT c.* FROM code c LEFT JOIN code_like l ON l.code_id = c.id GROUP BY c.id ORDER BY COUNT(*) DESC

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

Copy Clear