Sobes.tech
Junior — Middle

Kuidas saab piirata arvu või valida teatud kirjeid, täites SELECT käsu?

sobes.tech AI

Vastus AI-lt

To limit the number of records or select specific records when executing a SELECT statement in SQL, keywords and constructs are used:

  • LIMIT — limits the number of rows returned. For example, SELECT * FROM users LIMIT 10; will return the first 10 records.
  • WHERE — filters records based on a condition. For example, SELECT * FROM orders WHERE status = 'completed'; will select only completed orders.
  • OFFSET — skips a specified number of rows before starting to return results. For example, SELECT * FROM products LIMIT 10 OFFSET 20; will return 10 records starting from the 21st.

Example:

SELECT id, name FROM employees WHERE department = 'Sales' LIMIT 5;

This query will select the first 5 employees from the sales department.