Top 10 SQL Commands

0
SQL commands

SQL is a popular language for database management. It simplifies the interaction with the database. The SQL commands are used to update and retrieve data from the database. Some of the basic SQL commands which can be helpful for anyone are following,

1.SELECT

The SELECT command is used to display all the rows and columns from the table. For example, if we have a table “city” with the name of alle cities then we have to type,

SELECT *

FROM city;

This will display all the rows and columns of the table city.

2.WHERE

The WHERE command is used to show results based on some condition. For example, if we want to see cities from table “city” which have ZIP greater than 1345 then type,

SELECT *

FROM city

WHERE zip >1345;

3.BETWEEN

The BETWEEN command is used to display results which have a specific range. For instance, if we want to see cities which have ZIP code between 1345 and 1996 then type,

SELECT *

FROM city

BETWEEN zip> 1345 AND zip<1996;

4.LIMIT

The LIMIT command is used to define the limit of the result. For example, if we want to see only 10 cities in the result then we have to type,

SELECT *

FROM city

LIMIT 10;

This will only show the first 10 cities in the result.

5.GROUP BY

GROUP BY command is used to arrange identical data into groups with the help of some functions. It is used to group rows with same values. The GROUP BY clause is used together with SELECT statement. For example,

SELECT COUNT(studentID),

city FROM student

GROUP BY city;

6.ORDER BY DESC/ASC

ORDER BY DESC/ASC command is used to display result in an ascending or descending order. For instance, if we want to see cities in a descending order then we have to type,

SELECT *

FROM city

ORDER BY DESC;

7.INSERT INTO

INSERT INTO command is used to insert values into the table. For example, if we have a table “student” which has 3 rows namely studentID, fname and lname. If we want to enter values into these rows they we have to type,

INSERT INTO student(studentID, fname, lname)

VALUES (5055, ‘Maria’, ‘Jones’);

Values such as 5055, Maria and Jones have been stored in studentID, first name (fname) and last name (lname) respectively.

8.DELETE

The DELETE command is used to delete rows from a database. For example, if we want to delete a specific row from table student then we have to type,

DELETE FROM student

WHERE city=’Karachi’;

9.UPDATE

UPDATE command is used to either update a single or multiple rows at a time. For example, if we want to update the first name of a specific student in a table student then we have to type,

UPDATE student

SET fname=’Max’,

Lname=’Willy’

WHERE city=’Johannesburg’;

10.IS NULL

The IS NULL command is used to find empty values. To find empty values type,

SELECT fname, lname

FROM student

WHERE marks IS NULL;

LEAVE A REPLY

Please enter your comment!
Please enter your name here