Skip to main content

SQL Syntax

SQL (Structured Query Language) is a programming language used for managing and manipulating relational databases. Here's a basic overview of its syntax:


  1. SELECT: Used to retrieve data from a database.

SELECT column1, column2 FROM table_name WHERE condition;


Example


SELECT first_name, last_name FROM employees WHERE department = 'HR';




  1. INSERT INTO: Used to insert new records into a table.

INSERT INTO table_name (column1, column2) VALUES (value1, value2);


Example


INSERT INTO employees (first_name, last_name) VALUES ('John', 'Doe');



  1. UPDATE: Used to modify existing records in a table.

UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;


Example


UPDATE employees SET department = 'Finance' WHERE employee_id = 101;


  1. DELETE: Used to delete records from a table.

DELETE FROM table_name WHERE condition;


Example


DELETE FROM employee WHERE employee_id=102;


  1. CREATE TABLE: Used to create a new table in the database.

CREATE TABLE table_name (

    column1 datatype,

    column2 datatype,

    ...

);


Example


CREATE TABLE employees ( employee_id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50), department VARCHAR(50) );



  1. ALTER TABLE: Used to modify an existing table.

ALTER TABLE table_name ADD column_name datatype;


Example


ALTER TABLE employees ADD email VARCHAR(100);



  1. DROP TABLE: Used to delete a table and all its data from the database.

DROP TABLE table_name;


Example


DROP TABLE table_name;



  1. JOIN: Used to combine rows from two or more tables based on a related column.

SELECT * FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;



Example


SELECT orders.order_id, customers.customer_name FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;




  1. GROUP BY: Used to group rows that have the same values into summary rows.

SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;


Example


SELECT product_id, SUM(quantity) AS total_quantity FROM orders GROUP BY product_id;



  1. ORDER BY: Used to sort the result set in ascending or descending order.

SELECT * FROM table_name ORDER BY column_name ASC|DESC;


Example


SELECT * FROM customers ORDER BY last_name ASC;



These are some of the fundamental SQL commands and their syntax. The exact syntax may vary slightly depending on the database management system you are using (e.g., MySQL, PostgreSQL, SQLite, etc.), so it's always a good idea to consult the documentation specific to your database.

 

Comments

Popular posts from this blog

TechUplift: Elevating Your Expertise in Every Click

  Unlock the potential of data with SQL Fundamental: Master querying, managing, and manipulating databases effortlessly. Empower your database mastery with PL/SQL: Unleash the full potential of Oracle databases through advanced programming and optimization. Unlock the Potential of Programming for Innovation and Efficiency.  Transform raw data into actionable insights effortlessly. Empower Your Data Strategy with Power Dataware: Unleash the Potential of Data for Strategic Insights and Decision Making.

SQL Fundamentals

SQL, or Structured Query Language, is the go-to language for managing relational databases. It allows users to interact with databases to retrieve, manipulate, and control data efficiently. SQL provides a standardized way to define database structures, perform data operations, and ensure data integrity. From querying data to managing access and transactions, SQL is a fundamental tool for anyone working with databases. 1. Basics of SQL Introduction : SQL (Structured Query Language) is used for managing and manipulating relational databases. SQL Syntax : Basic structure of SQL statements (e.g., SELECT, INSERT, UPDATE, DELETE). Data Types : Different types of data that can be stored (e.g., INTEGER, VARCHAR, DATE). 2. SQL Commands DDL (Data Definition Language) : CREATE TABLE : Define new tables. ALTER TABLE : Modify existing tables. DROP TABLE : Delete tables. DML (Data Manipulation Language) : INSERT : Add new records. UPDATE : Modify existing records. DELETE : Remove records. DQL (Da...

DAX Functions

These are just some of the many DAX functions available in Power BI. Each  function serves a specific purpose and can be used to perform a wide range of calculations and transformations on your data. Aggregation Functions: SUM : Calculates the sum of values. AVERAGE : Calculates the arithmetic mean of values. MIN : Returns the smallest value in a column. MAX : Returns the largest value in a column. COUNT : Counts the number of rows in a table or column. COUNTA : Counts the number of non-blank values in a column. DISTINCTCOUNT : Counts the number of unique values in a column. Logical Functions: IF : Returns one value if a condition is true and another value if it's false. AND : Returns TRUE if all the conditions are true, otherwise FALSE. OR : Returns TRUE if any of the conditions are true, otherwise FALSE. NOT : Returns the opposite of a logical value. Text Functions: CONCATENATE : Concatenates strings together. LEFT : Returns the leftmost characters from a text string. RIGHT : Ret...