EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

SQL Commands

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » SQL Tutorial » SQL Commands

SQL Commands

Introduction to SQL Commands

SQL or popularly known as Structured Query Language, is the fundamental query language for databases and is a domain-specific language for Relational Database Management Systems. It is useful when the data type is structured and there exists a dependency among the various attributes of data. It is widely used and is one of the most popular query languages for its unique capability of fetching multiple records by just making use of a single query statement. It consists of both DDL (Data Definition Language) and DML(Data Manipulation Language) commands which makes the use of queries much more efficient. SQL is a declarative programming language that is set-based and is therefore not an imperative programming language such as C or BASIC, etc. In order to fetch the data results from the database, you need to know SQL commands which we are going to study in this post.

Basic SQL Commands

The basic commands are given below.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

1. SELECT: This is possibly the most basic SQL command. The select command is used to fetch or retrieve results from a particular table of a database. This is generally followed by specific column names or all column names (by making use of * ).

Basic SQL Commands Select

2. CREATE: This is one of the basic DDL commands which is used to create a table inside a database. The prerequisites of creating a table include knowing column name and their datatypes.

Basic SQL Commands Create

3. ALTER: This DML command is used to make alterations to the table. It includes modifying the table as per the need.

Basic SQL Commands Alter

4. WHERE: The WHERE clause is one of the most important SQL commands as it is used to retrieve or fetch the specific data that is required for a particular case. This is helpful as it excludes all the irrelevant data.

Where

5. SQL ALIAS: The ALIAS is among the most common SQL command which is used to give a meaningful name to your attribute or a column. They are defined for columns and tables, which helps in increasing the readability of the query.

SQL Alias

6. AND: This is an SQL operator which is used to combine two conditions. For the row to appear in the data result set, both the conditions should be true.

Basic SQL Commands AND

7. AVG(): This is an aggregate function that is used to return the average value of a particular numeric column.

AVG()

8. ORDER BY: This is used along with the select statement to sort the results either in ascending order or descending order. If no argument is given after the ORDER BY clause, it by default takes as the ascending order query.

Basic SQL Commands ORDER by

9. GROUP BY: The GROUP BY clause in the SQL commands is used to retrieve the data on the basis of some particular grouping related to one or more columns.

Popular Course in this category
Sale
SQL Training Program (7 Courses, 8+ Projects)7 Online Courses | 8 Hands-on Projects | 73+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,933 ratings)
Course Price

View Course

Related Courses
JDBC Training (6 Courses, 7+ Projects)PHP Training (5 Courses, 3 Project)Windows 10 Training (4 Courses, 4+ Projects)PL SQL Training (4 Courses, 2+ Projects)Oracle Training (14 Courses, 8+ Projects)

GROUP BY

10. INSERT: The INSERT command is used to add a new row of data inside the table. The mandate for the INSERT command is that the table should be already created.

Insert

Intermediate Commands

The intermediate commands are given below:

1. UPDATE: This command is used to update or modify the existing rows in a table.

Intermediate SQL Commands UPDATE 1

2. DELETE: As the name suggests, this command is used to delete the rows from a table.

Deleted

3. HAVING: The HAVING clause is used to filter the data based on one or more group functions. This is quite very similar to using a WHERE clause but this includes the use by a group function.

Intermediate SQL Commands Having

4. LIKE: This operator is used to compare between the two conditions and lists down all the rows of a table whose column name matches the pattern specified with the LIKE clause. Wildcard operators such as % are used when you are not sure about the particular pattern.

Like

5. IN: The IN operator when the comparison of a column is made with multiple values. It is more or less similar to the OR condition.

In

6. IS NULL: The IS NULL operator is another SQL-based operator which is used to display whether the particular column name has a NULL value. It is used to fetch all the rows for the specified columns for which the data has not been found or has been found as null.

Is null

7. BETWEEN: As the name suggests, this operator filters the results for a particular set of ranges. The value, in this case, can either be numbers, dates or text.

Between

8. CASE: This case is the same as used in other programming languages such as Java, etc., where a decision control statement is taken by the case statement and the argument inside it is used to fetch the case results matching the particular condition.

Intermediate SQL Commands CASE

9. COUNT(): This is one of the most useful SQL commands which is used to display the count of the total number of rows for all those non-null data. It makes use of the column name as the argument.

COUNT

10. INNER JOIN: This is one of the most important SQL commands which comes into play when there has to build a relationship among the attributes of two tables based on a fixed common attribute. In other words, the join condition has to be true in order for INNER JOIN to function.

Inner join

Advanced SQL Commands

The advanced commands are given below:

1. LIMIT: The LIMIT clause will help you specify the maximum number of rows that are allowed in the result set.

Advanced SQL Commands Limit

2. OUTER JOIN: This is the join function that comes into play when all the fields of both tables are required based on some common input column condition. If the join condition is not met, then a NULL value will be filled on the right side of the column.

Outer join

Tips and Tricks to use SQL Commands

Whenever you are using SQL commands, spend more time analyzing the table than querying and executing it. Make use of simpler and less complex queries with minimum use of dynamic SQL. Also, we prefer to use a table alias for better readability.

Conclusion

This post was about the important SQL commands which form the base of the database querying language.

Recommended Articles

This has been a guide to SQL Commands. Here we have discussed basic, intermediate as well as advanced SQL commands along with tips and tricks to use. You may also look at the following article to learn more-

  1. SQL GROUP BY WHERE
  2. SQL Server Versions
  3. SQL now
  4. sql projects

SQL Training Program (7 Courses, 8+ Projects)

7 Online Courses

8 Hands-on Projects

73+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
SQL Tutorial
  • Commands
    • SQL Commands
    • sqlplus set commands
    • SQL Alter Command
    • SQL Commands Update
    • SQL DML Commands
    • SQL DDL Commands
    • FETCH in SQL
  • Basic
    • What is SQL
    • Careers in SQL
    • Careers in SQL Server
    • IS SQL Microsoft?
    • SQL Management Tools
    • What is SQL Developer
    • Uses of SQL
    • How to Install SQL Server
    • What is SQL Server
    • SQL Server Versions
    • SQL Case Insensitive
    • SQL Expressions
    • Database in SQL
    • SQL Data Types
    • SQL Keywords
    • Composite Key in SQL
    • SQL WAITFOR
    • SQL Constraints
    • Transactions in SQL
    • First Normal Form
    • SQL Server Data Types
    • SQL Administration
    • SQL Variables
    • SQL Enum
    • SQL GROUP BY WHERE
    • SQL ROW
    • SQL EXECUTE
    • SQL EXCLUDE
    • SQL Performance Tuning
    • SQL UUID
    • Begin SQL
    • SQL Update Join
    • Cheat sheet SQL
  • Operators
    • SQL Operators
    • SQL Arithmetic Operators
    • SQL Logical Operators
    • SQL String Operators
    • Ternary Operator in SQL
  • Clause
    • SQL Clauses
    • SQL IN Operator
    • SQL LIKE Clause
    • SQL NOT Operator
    • SQL Minus
    • SQL WHERE Clause
    • SQL with Clause
    • SQL HAVING Clause
    • GROUP BY clause in SQL
    • SQL GROUP BY DAY
    • ORDER BY Clause in SQL
    • SQL ORDER BY CASE
    • SQL ORDER BY DESC
    • SQL ORDER BY DATE
    • SQL ORDER BY Alphabetical
    • SQL ORDER BY Ascending
    • SQL Order by Count
    • SQL GROUP BY Month
    • SQL GROUP BY Multiple Columns
    • SQL GROUPING SETS
  • Queries
    • SQL Insert Query
    • SQL SELECT Query
    • SQL SELECT RANDOM
    • SQL Except Select
    • SQL Subquery
    • SQL SELECT DISTINCT
    • SQL WITH AS Statement
  • Keys
    • SQL Keys
    • Primary Key in SQL
    • Foreign Key in SQL
    • Unique Key in SQL
    • Alternate Key in SQL
    • SQL Super Key
  • Functions
    • SQL Date Function
    • SQL String Functions
    • SQL Compare String
    • Timestamp to Date in SQL
    • SQL Window Functions
    • SQL CONCAT
    • SQL ALTER TABLE
    • SQL MOD()
    • SQL Timestamp
    • SQL TO_DATE()
    • SQL DATEADD()
    • SQL DATEDIFF()
    • SQL HOUR()
    • SQLite?functions
    • ANY in SQL
    • LIKE Query in SQL
    • SQL NOT NULL
    • SQL NOT IN
    • SQL MAX()
    • SQL MIN()
    • SQL SUM()
    • SQL COUNT
    • SQL identity
    • SQL DELETE Trigger
    • SQL Declare Variable
    • SQL Text Search
    • SQL COUNT DISTINCT
    • SQL TEXT
    • SQL Limit Order By
    • BETWEEN in SQL
    • LTRIM() in SQL
    • TOP in SQL
    • SQL Select Top
    • Merge SQL
    • SQL TRUNCATE()
    • SQL UNION
    • SQL ALL
    • SQL INTERSECT
    • SQL Alias
    • SQL Server Substring
    • CUBE in SQL
    • SQL RANK()
    • SQL MOD()
    • SQL CTE
    • SQL LAG()
    • SQL MID
    • SQL avg()
    • SQL WEEK
    • SQL DELETE
    • SQL DATEPART()
    • SQL DECODE()
    • SQL DENSE_RANK()
    • SQL NTILE()
    • SQL NULLIF()
    • SQL Stuff
    • SQL Ceiling
    • SQL EXISTS
    • SQL LEAD()
    • SQL COALESCE
    • SQL BLOB
    • SQL ROW_NUMBER
    • SQL Server Replace
    • SQL Server Permission
    • T-SQL INSERT
    • T-SQL Stuff
    • T-SQL ADD Column
    • SQL Ranking Function
  • Joins
    • Join Query in SQL
    • Types of Joins in SQL
    • Types of Joins in SQL Server
    • SQL Inner Join
    • SQL Join Two Tables
    • SQL Delete Join
    • SQL Left Join
    • LEFT OUTER JOIN in SQL
    • SQL Right Join
    • SQL Cross Join
    • SQL Outer Join
    • SQL Full Join
    • SQL Self Join
    • Natural Join SQL
    • SQL Multiple Join
  • Advanced
    • SQL Formatter
    • SQL Injection Attack
    • Aggregate Functions in SQL
    • SQL REVOKE
    • SQL Select Distinct Count
    • IF ELSE Statement in SQL
    • SQL CASE Statement
    • SQL While Loop
    • SQL BIGINT
    • SQL Crosstab
    • SQL Wildcard Character
    • SQLAlchemy Filter
    • SQLAlchemy SQLite
    • SQLAlchemy DateTime
    • SQLAlchemy create_engine
    • SQL INSTR()
    • SQL now
    • SQL synonyms
    • SQLite?export to csv
    • What is Procedure in SQL
    • Stored Procedure in SQL?
    • SQL Server Constraints
    • SQL DELETE ROW
    • Column in SQL
    • Table in SQL
    • SQL Virtual Table
    • SQL Merge Two Tables
    • SQL Table Partitioning
    • SQL Temporary Table
    • SQL Clone Table
    • SQL Rename Table
    • SQL LOCK TABLE
    • SQL Clear Table
    • SQL DESCRIBE TABLE
    • SQL Mapping
    • Cursors in SQL
    • AND in SQL
    • Wildcard in SQL
    • SQL FETCH NEXT
    • SQL Views
    • SQL Delete View
    • Triggers in SQL
    • SQL UPDATE Trigger
    • SQL AFTER UPDATE Trigger
    • SQL Update Statement
    • SQL DROP TRIGGER
    • Types of SQL Views
    • SQL Port
    • SQL Clustered Index
    • SQL COMMIT
    • Distinct Keyword in SQL
    • PARTITION BY in SQL
    • SQL Set Operators
    • SQL UNION ALL
    • Metadata in SQL
    • SQL Bulk Insert
    • Array in SQL
    • SQL REGEXP
    • JSON in SQL
    • SQL For loop
    • EXPLAIN in SQL
    • ROLLUP in SQL
    • Escape Character SQL
    • SQL Cluster
    • SQL Backup
    • SQL Pattern Matching
    • SQL Users
    • ISNULL SQL Server
    • SQL pivot
    • SQL Import CSV
    • SQL if then else
    • SQL ignore-case
    • SQL Matches
    • SQL Search String
    • SQL Column Alias
    • SQL extensions
    • SQL Substring Function
    • Charindex SQL
  • NoSQ
    • NoSQL Databases List
    • NoSQL Injection
    • NoSQL vs SQL Databases
  • Interview Questions
    • SQL Interview Questions
    • Advance SQL Interview Questions
    • SQL Joins Interview Questions
    • SQL Server Interview Questions

Related Courses

JDBC Training Course

PHP course

Windows 10 Training

SQL Course Training

PL/SQL Certification Courses

Oracle Certification Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Special Offer - SQL Training Program (7 Courses, 8+ Projects) Learn More