menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Databases

>

SQL Basic ...
source image

Dev

1w

read

393

img
dot

Image Credit: Dev

SQL Basic to Advanced Queries

  • Use SELECT * FROM table_name; when you need to retrieve all columns from a table.
  • Use SELECT column1, column2 FROM table_name; when you only need specific columns.
  • Use SELECT * FROM table_name WHERE condition; to filter results based on a condition.
  • Use SELECT * FROM table_name ORDER BY column_name [ASC|DESC]; to sort the results by a specific column in ascending or descending order.
  • Use SELECT * FROM table_name LIMIT number; to limit the number of rows returned by the query.
  • Use SELECT DISTINCT column_name FROM table_name; to remove duplicate rows from the result set.
  • Use SELECT COUNT(column_name) FROM table_name; to count the number of rows that match a specified condition.
  • Use SELECT SUM(column_name) FROM table_name; to calculate the total sum of a numeric column.
  • Use SELECT AVG(column_name) FROM table_name; to calculate the average value of a numeric column.
  • Use SELECT MIN(column_name) FROM table_name; to find the minimum value in a column.
  • Use SELECT MAX(column_name) FROM table_name; to find the maximum value in a column.
  • Use INNER JOIN to combine rows from two tables based on a related column between them.
  • Use LEFT JOIN to get all rows from the left table and the matched rows from the right table.
  • Use RIGHT JOIN to get all rows from the right table and the matched rows from the left table.
  • Use GROUP BY to group rows that have the same values in specified columns into summary rows.
  • Use SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > 1; to filter groups based on a condition.
  • Use CASE to perform conditional logic in SQL queries.
  • Use UNION to combine the results of two or more SELECT statements without duplicates.
  • Use UNION ALL to combine the results of two or more SELECT statements with duplicates.
  • Use CREATE INDEX to improve the performance of queries that filter or sort by indexed columns.

Read Full Article

like

23 Likes

For uninterrupted reading, download the app