Menu

1 / 2

SQL Queries Every Developer Should Know (With Examples)

DEV Community·Alex Chen·6 months ago
#enzZiwQd
#sql#beginners#database#select#users
Reading 0:00
15s threshold

SQL Queries Every Developer Should Know (With Examples)

You don't need to be a DBA. But you DO need to write queries.

The Basics

-- SELECT: Read data SELECT name , email FROM users WHERE active = 1 ;

-- INSERT: Add data INSERT INTO users ( name , email , role ) VALUES ( 'Alex' , '[email protected]' , 'user' );

-- UPDATE: Change data UPDATE users SET role = 'admin' WHERE id = 123 ;

-- DELETE: Remove data DELETE FROM users WHERE id = 123 ;

Enter fullscreen mode

Exit fullscreen mode

Filtering and Sorting

-- WHERE clauses SELECT * FROM products WHERE price > 100 ; SELECT * FROM users WHERE name LIKE 'A%' ; -- Starts with 'A' SELECT * FROM users WHERE email LIKE '%@gmail.com' ; -- Ends with @gmail.com SELECT * FROM orders WHERE status IN ( 'pending' , 'shipped' ); SELECT * FROM users WHERE age BETWEEN 18 AND 65 ; SELECT * FROM users WHERE bio IS NULL ; -- Check for NULL (not = NULL)

-- AND / OR / NOT SELECT * FROM users WHERE active = 1 AND ( role = 'admin' OR role = 'moderator' );

-- ORDER BY SELECT *…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.