DEV Community

Vera-778
Vera-778

Posted on

Fundamental SQL concepts

Hi guys, this is the first day I learn IT (officially). I decide to take notes about whatever I think important and related. Hopefully I can form a network of knowledge one day.
It would be so ideal if someone read my posts and help me improve. All suggestions are welcomed. Learning is detemined to be a road of loneliness, but one will go further with other lonely geeks. That's what I thought the meaning of communities.

1. SELECT Statement:

  • The SELECT statement is used to retrieve data from one or more tables.
   SELECT column1, column2
   FROM table_name;
Enter fullscreen mode Exit fullscreen mode

2. FROM Clause:

  • The FROM clause specifies the table or tables from which to retrieve data.
   SELECT column1, column2
   FROM employees;
Enter fullscreen mode Exit fullscreen mode

3. WHERE Clause:

  • The WHERE clause is used to filter rows based on specific conditions.
   SELECT column1, column2
   FROM table_name
   WHERE condition;
Enter fullscreen mode Exit fullscreen mode

4. AND, OR, NOT Operators:

  • Combine conditions using AND, OR, and NOT operators in the WHERE clause.
   SELECT column1, column2
   FROM table_name
   WHERE condition1 AND condition2;
Enter fullscreen mode Exit fullscreen mode

5. ORDER BY Clause:

  • The ORDER BY clause is used to sort the result set based on one or more columns.
   SELECT column1, column2
   FROM table_name
   ORDER BY column1 ASC;
Enter fullscreen mode Exit fullscreen mode

6. INSERT INTO Statement:

  • The INSERT INTO statement is used to insert new records into a table.
   INSERT INTO table_name (column1, column2)
   VALUES (value1, value2);
Enter fullscreen mode Exit fullscreen mode

7. UPDATE Statement:

  • The UPDATE statement is used to modify existing records in a table.
   UPDATE table_name
   SET column1 = value1, column2 = value2
   WHERE condition;
Enter fullscreen mode Exit fullscreen mode

8. DELETE Statement:

  • The DELETE statement is used to remove records from a table.
   DELETE FROM table_name
   WHERE condition;
Enter fullscreen mode Exit fullscreen mode

9. JOIN Clause:

  • The JOIN clause is used to combine rows from two or more tables based on a related column.
   SELECT column1, column2
   FROM table1
   INNER JOIN table2 ON table1.column = table2.column;
Enter fullscreen mode Exit fullscreen mode

10. GROUP BY Clause:

- The `GROUP BY` clause is used to group rows based on one or more columns, often used with aggregate functions.
Enter fullscreen mode Exit fullscreen mode
```sql
SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1;
```
Enter fullscreen mode Exit fullscreen mode

11. HAVING Clause:

- The `HAVING` clause is used with the `GROUP BY` clause to filter the results based on aggregate values.
Enter fullscreen mode Exit fullscreen mode
```sql
SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1
HAVING COUNT(*) > 10;
```
Enter fullscreen mode Exit fullscreen mode

12. Aliases:

- Use aliases to provide temporary names for columns or tables in your queries.
Enter fullscreen mode Exit fullscreen mode
```sql
SELECT column1 AS alias1, column2 AS alias2
FROM table_name;
```
Enter fullscreen mode Exit fullscreen mode

13. Comments:

- Use `--` for single-line comments or `/* */` for multi-line comments.
Enter fullscreen mode Exit fullscreen mode
```sql
-- This is a single-line comment

/*
This is a
multi-line comment
*/
```
Enter fullscreen mode Exit fullscreen mode

Top comments (0)