SQL Tutorial: Learn SQL for Free
Welcome to our SQL tutorial, where you'll learn SQL (Structured Query Language) step-by-step in a simple and practical manner. This guide covers essential SQL concepts to help you progress from basic to advanced levels. Whether you're just starting or looking to strengthen your database programming skills, this tutorial is for you.
Example: SQL Query
Consider the following table, CUSTOMERS, which stores customer details:
ID | Name | Age | Salary | City | Country |
---|---|---|---|---|---|
1 | Ramesh | 32 | 2000.00 | Maryland | USA |
2 | Reena | 40 | 5000.00 | New York | USA |
3 | Ankit | 29 | 4500.00 | Muscat | Oman |
To retrieve customers from the USA, use the following SQL query:
Syntax
SELECT * FROM CUSTOMERS WHERE country = 'USA';
Output
ID Name Age Salary City Country
1 Ramesh 32 2000.00 Maryland USA
2 Reena 40 5000.00 New York USA
Basic SQL Commands
Here are standard SQL commands, categorized into groups:
-
Data Definition Language (DDL): Commands to define and modify database structure.
- CREATE: Create new tables or database objects.
- ALTER: Modify existing database objects.
- DROP: Delete tables or database objects.
- TRUNCATE: Remove all records from a table.
-
Data Manipulation Language (DML): Commands to manipulate database data.
- SELECT: Retrieve specific data.
- INSERT: Add new data.
- UPDATE: Modify existing data.
- DELETE: Remove data.
-
Data Control Language (DCL): Commands to manage data access.
- GRANT: Assign access permissions.
- REVOKE: Remove access permissions.
Why Learn SQL?
SQL is essential for students and professionals in software development, banking, finance, and many other domains. It is widely used in applications to manage and manipulate data efficiently. Learning SQL enhances your programming skills and career prospects.
SQL Applications
SQL allows you to:
- Query data from databases.
- Define and manipulate database structures.
- Create views, procedures, and functions.
- Manage database user access and permissions.
SQL Online Quizzes
Test your SQL knowledge with our quizzes and assignments. Here's a sample question:
Question: Who developed SQL?
- A. Google in the 1990s
- B. Microsoft in the 1980s
- C. IBM in the 1970s
- D. None of the above
Answer: IBM in the 1970s
- SQL Home
- SQL Introduction
- SQL Syntax
- SQL SELECT
- SQL DISTINCT
- SQL WHERE
- SQL ORDER BY
- SQL AND
- SQL OR
- SQL NOT
- SQL INSERT
- SQL NULL Values
- SQL UPDATE
- SQL DELETE
- SQL TOP
- SQL Aggregate Functions
- SQL MIN and MAX
- SQL COUNT
- SQL SUM
- SQL AVG
- SQL LIKE
- SQL Wildcards
- SQL IN
- SQL BETWEEN
- SQL Alias
- SQL JOIN
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL Self JOIN
- SQL UNION
- SQL GROUP BY
- SQL HAVING
- SQL EXISTS
- SQL ANY and ALL
- SQL SELECT INTO
- SQL INSERT INTO SELECT
- SQL CASE
- SQL ISNULL
- SQL Stored Procedures
- SQL Comments
- SQL Operators
- SQL Create Database
- SQL Drop Database
- SQL Backup Database
- SQL Create Table
- SQL Drop Table
- SQL ALTER
- SQL Constraints
- SQL NOT NULL
- SQL UNIQUE
- SQL PRIMARY KEY
- SQL FOREIGN KEY
- SQL CHECK
- SQL DEFAULT
- SQL Create Index
- SQL Auto Increment
- SQL Dates
- SQL View
- SQL Injection
- SQL Hosting
- SQL Data Types
- SQL Keywords
- SQL ADD
- SQL ADD CONSTRAINT
- SQL ALL
- SQL ALTER
- SQL ALTER COLUMN
- SQL ALTER TABLE
- SQL AND
- SQL ANY
- SQL AS
- SQL ASC
- Backup Database
- BETWEEN
- CASE
- CHECK
- COLUMN
- CONSTRAINT
- CREATE
- CREATE DATABASE
- CREATE INDEX
- CREATE OR REPLACE VIEW
- CREATE TABLE
- CREATE PROCEDURE
- CREATE UNIQUE INDEX
- CREATE VIEW
- DATABASE
- DEFAULT
- DELETE
- DESC
- DISTINCT
- DROP
- DROP COLUMN
- DROP CONSTRAINT
- DROP DATABASE
- DROP DEFAULT
- DROP INDEX
- DROP TABLE
- DROP VIEW
- EXEC
- EXISTS
- FOREIGN KEY
- FROM
- FULL OUTER JOIN
- GROUP BY
- HAVING
- IN
- INDEX
- INNER JOIN
- INSERT INTO
- INSERT INTO SELECT
- IS NULL
- IS NOT NULL
- JOIN
- LEFT JOIN
- LIKE
- LIMIT
- NOT
- NOT NULL
- OR
- ORDER BY
- OUTER JOIN
- PRIMARY KEY
- PROCEDURE
- RIGHT JOIN
- ROWNUM
- SELECT
- SELECT DISTINCT
- SELECT INTO
- SELECT TOP
- SET
- TABLE
- TOP
- TRUNCATE TABLE
- UNION
- UNION ALL
- UNIQUE
- UPDATE
- VALUES
- VIEW
- WHERE
- MySQL Specifics
- ASCII
- CHAR_LENGTH
- CHARACTER_LENGTH
- CONCAT
- CONCAT_WS
- FIELD
- FIND_IN_SET
- FORMAT
- INSERT
- INSTR
- LCASE
- LEFT
- LENGTH
- LOCATE
- LOWER
- LPAD
- LTRIM
- MID
- POSITION
- REPEAT
- REPLACE
- REVERSE
- RIGHT
- RPAD
- RTRIM
- SPACE
- STRCMP
- SUBSTR
- SUBSTRING
- SUBSTRING_INDEX
- TRIM
- UCASE
- UPPER
- ABS
- ACOS
- ASIN
- ATAN
- ATAN2
- AVG
- CEIL
- CEILING
- COS
- COT
- COUNT
- DEGREES
- DIV
- EXP
- FLOOR
- GREATEST
- LEAST
- LN
- LOG
- LOG10
- LOG2
- MAX
- MIN
- MOD
- PI
- POW
- POWER
- RADIANS
- RAND
- ROUND
- SIGN
- SIN
- SQRT
- SUM
- TAN
- TRUNCATE
- ADDDATE
- ADDTIME
- CURDATE
- CURRENT_DATE
- CURRENT_TIME
- CURRENT_TIMESTAMP
- CURTIME
- DATE
- DATEDIFF
- DATE_ADD
- DATE_FORMAT
- DATE_SUB
- DAY
- DAYNAME
- DAYOFMONTH
- DAYOFWEEK
- DAYOFYEAR
- EXTRACT
- FROM_DAYS
- HOUR
- LAST_DAY
- LOCALTIME
- LOCALTIMESTAMP
- MAKEDATE
- MAKETIME
- MICROSECOND
- MINUTE
- MONTH
- MONTHNAME
- NOW
- PERIOD_ADD
- PERIOD_DIFF
- QUARTER
- SECOND
- SEC_TO_TIME
- STR_TO_DATE
- SUBDATE
- SUBTIME
- SYSDATE
- TIME
- TIME_FORMAT
- TIME_TO_SEC
- TIMEDIFF
- TIMESTAMP
- TO_DAYS
- WEEK
- WEEKDAY
- func-mysql-weekofyear
- func-mysql-year
- func-mysql-yearweek
- func-mysql-bin
- func-mysql-binary
- func-mysql-case
- func-mysql-cast
- func-mysql-coalesce
- func-mysql-connection-id
- func-mysql-conv
- func-mysql-convert
- func-mysql-current-user
- func-mysql-database
- func-mysql-if
- func-mysql-ifnull
- func-mysql-isnull
- func-mysql-last-insert-id
- func-mysql-nullif
- func-mysql-session-user
- func-mysql-system-user
- func-mysql-user
- func-mysql-version
- sql-ref-sqlserver
- func-sqlserver-ascii
- func-sqlserver-char
- func-sqlserver-charindex
- func-sqlserver-concat
- func-sqlserver-concat-with-plus
- func-sqlserver-concat-ws
- func-sqlserver-datalength
- func-sqlserver-difference
- func-sqlserver-format
- func-sqlserver-left
- func-sqlserver-len
- func-sqlserver-lower
- func-sqlserver-ltrim
- func-sqlserver-nchar
- func-sqlserver-patindex
- func-sqlserver-quotename
- func-sqlserver-replace
- func-sqlserver-replicate
- func-sqlserver-reverse
- func-sqlserver-right
- func-sqlserver-rtrim
- func-sqlserver-soundex
- func-sqlserver-space
- func-sqlserver-str
- func-sqlserver-stuff
- func-sqlserver-substring
- func-sqlserver-translate
- func-sqlserver-trim
- func-sqlserver-unicode
- func-sqlserver-upper
- func-sqlserver-abs
- func-sqlserver-acos
- func-sqlserver-asin
- func-sqlserver-atan
- ATN2
- AVG
- CEILING
- COUNT
- COS
- COT
- DEGREES
- EXP
- FLOOR
- LOG
- LOG10
- MAX
- MIN
- PI
- POWER
- RADIANS
- RAND
- ROUND
- SIGN
- SIN
- SQRT
- SQUARE
- SUM
- TAN
- CURRENT_TIMESTAMP
- DATEADD
- DATEDIFF
- DATEFROMPARTS
- DATENAME
- DATEPART
- DAY
- GETDATE
- GETUTCDATE
- ISDATE
- MONTH
- SYSDATETIME
- YEAR
- CAST
- COALESCE
- CONVERT
- CURRENT_USER
- IIF
- ISNULL
- ISNUMERIC
- NULLIF
- SESSION_USER
- SESSIONPROPERTY
- SYSTEM_USER
- USER_NAME
- MS Access SQL Reference
- ASC
- CHR
- CONCAT
- CURDIR
- FORMAT
- INSTR
- INSTRREV
- LCASE
- LEFT
- LEN
- LTRIM
- MID
- REPLACE
- RIGHT
- RTRIM
- SPACE
- SPLIT
- STR
- STRCOMP
- STRCONV
- STRREVERSE
- TRIM
- UCASE
- ABS
- ATN
- AVG
- COS
- COUNT
- EXP
- FIX
- Format (Number)
- INT
- MAX
- MIN
- RANDOMIZE
- RND
- ROUND
- SGN
- SQR
- SUM
- VAL
- DATE
- DATEADD
- DATEDIFF
- DATEPART
- DATESERIAL
- DATEVALUE
- DAY
- Format (Date)
- HOUR
- MINUTE
- MONTH
- MONTHNAME
- NOW
- SECOND
- TIME
- TIMESERIAL
- TIMEVALUE
- WEEKDAY
- WEEKDAYNAME
- YEAR
- CURRENTUSER
- MS Access Environ Function
- MS Access IsDate Function
- MS Access IsNull Function
- MS Access IsNumeric Function
- SQL Quick Reference
- SQL Examples