Show List

SQL syntax and keywords

SQL (Structured Query Language) is a standard language for managing and manipulating relational databases. Here are some of the common SQL syntax and keywords, along with examples:

  • SELECT: used to retrieve data from one or more tables in a database. Example:

sql
Copy code
SELECT column1, column2, column3 FROM table_name;
  • FROM: used to specify the table from which to retrieve data. Example:

  • sql
    Copy code
    SELECT column1, column2, column3 FROM table_name;
  • WHERE: used to filter the data based on specific conditions. Example:

  • sql
    Copy code
    SELECT column1, column2, column3 FROM table_name WHERE column1 = 'value';
  • AND/OR: used to combine multiple conditions in a WHERE clause. Example:

  • sql
    Copy code
    SELECT column1, column2, column3 FROM table_name WHERE column1 = 'value1' AND column2 = 'value2';
  • LIKE: used to match patterns in a WHERE clause. Example:

  • sql
    Copy code
    SELECT column1, column2, column3 FROM table_name WHERE column1 LIKE 'value%';
  • INNER JOIN: used to combine rows from two or more tables based on a related column between them. Example:

  • sql
    Copy code
    SELECT table1.column1, table2.column2 FROM table1 INNER JOIN table2 ON table1.column1 = table2.column1;
  • LEFT JOIN/RIGHT JOIN: used to combine rows from two tables, with the left join returning unmatched rows from the left table and the right join returning unmatched rows from the right table. Example:

  • sql
    Copy code
    SELECT table1.column1, table2.column2 FROM table1 LEFT JOIN table2 ON table1.column1 = table2.column1;
  • ORDER BY: used to sort the data in ascending or descending order. Example:

  • sql
    Copy code
    SELECT column1, column2, column3 FROM table_name ORDER BY column1 DESC;
  • GROUP BY: used to group data based on one or more columns. Example:

  • sql
    Copy code
    SELECT column1, SUM(column2) FROM table_name GROUP BY column1;
  • HAVING: used to filter the data after it has been grouped. Example:

  • sql
    Copy code
    SELECT column1, SUM(column2) FROM table_name GROUP BY column1 HAVING SUM(column2) > 100;

    These are just a few examples of the basic syntax and keywords used in SQL. The specific syntax and keywords used may vary depending on the database management system being used.


        Leave a Comment


    • captcha text