Learn SQL : How to delete the data from the table, The select statement and Interview questions related to it.
Deletion Of Data and The Select Statement in SqL DataBase.
If you want to drop or delete the table then use:
DROP TABLE table_name;
Example: DROP TABLE stu_data;
This will delete the entire table from the database. And now if you use the select command with previous table then it will give an error as shown below:
SELECT STATEMENT:
It is the most commonly used command to query the database and to retrieve the data.For retrieving the whole data, syntax is:
SELECT * FROM table_name;
SELECT col_1, col_2 FROM table_name;
- The first SELECT statement select 'ALL' columns i.e, it retrieve whole data from the table.
- While the second SELECT statement select the data from the particular column (col_1 and col_2).
1. SELECT * FROM customer;
- It retrieves all the data as shown above.
2. SELECT ID, Name, Salary FROM customer;
We will get:
3. SELECT * FROM customer where ID=6;
4. SELECT with AND operator:
It will return the result only when both the condition is true otherwise it return empty set.
Example:
5. SELECT WITH OR:
It will give the result for both the condition.
Example:
- Similarly, we can apply different operator with SELECT like:
>= = It mean greater than equal to.
> = It mean greater than.
- We can apply these operator along with 'AND' and 'OR'.
SELECT with LIKE
To save the time because of long SELECT statement, we can use LIKE keyword if the data has same character set present at the end of records.
SYNTAX: SELECT * FROM table_name WHERE col name LIKE '%characters';
Example: SELECT * FROM customer WHERE Name LIKE '%a';
- We can also select particular columns by writing the name of column which we want to see instead of *.
How to SELECT the ranges using AND and comparison statement:
Example: SELECT * FROM customer WHERE Salary>=25000 AND Salary<= 70000;
Another way of comparison of data is using BETWEEN keyword:
Example : SELECT * FROM customer WHERE Salary BETWEEN 24000 AND 70000;
INTERVIEW QUESTIONS:
1. How to get all the data from the table?
2. How to get data from the particular column?
3. What is the use of LIKE?
In case of any error related to data plz mail to: anshika.chaudhary2510@gmail.com
Previous Next
No comments: