SQL Basics — Part II

Geek Chic
2 min readNov 10, 2022

First read : SQL Basics — Part I

This blog solely focusses on writing SQL queries.

Query Basics

  • WHERE it let’s you filter the results of the query based on conditions that you specify.
  • ORDER BY sorts the list.
  • LIMIT returns the number of rows you specified.
  • AS renames.
  • DISTINCT return unique values.
  • AND and OR combines multiple conditions.
  • LIKE and BETWEEN are special operators.
  • CASE creates different cases.

Let’s dive more into the syntax.

P.S. Throughout the syntax I’ve written columnX which can be column1 OR column2 OR column3…

WHERE

SELECT column1, column2, column3..
FROM table_name
WHERE columnX operator value;

It can have the following operators:

  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to
  • = equal to
  • != not equal to

ORDER BY

SELECT column1, column2, column3..
FROM table_name
ORDER BY columnX
// OR
SELECT column1, column2, column3..
FROM table_name
ORDER BY columnX ASC // Can also be DESC

--

--