Important Queries in SQL Part1.
Hi Everyone,
We already Discussed about Oracle SQL and PL/SQL in my previous blogs . Today i will discuss about some important queries which is useful for you . For previous blogs you can able to see it in archive folder.
Let's Start with Important Queries which is useful for you to writing SQL queries . As in my previous blogs i already discussed about Joins , co-related and sub query . So today we will write some important queries which will be useful for you .
How do we Join 3 tables by using Inner Join ?
Explanation: Suppose we have 3 tables student , student_details and student_details1 with one common id in all the three tables.
We can write below query to Join 3 tables by using inner join:
SELECT
a.ID, a.Name,
b.address
FROM
student AS a
INNER JOIN student_details AS b
ON a.ID = b.ID
INNER JOIN student_details1 AS c
ON b.id = c.id;
Below is the output of above query in image :
Here you can see the output by Joining 3 tables by using Inner Join. For reference you can go through my Oracle Join Blogs.
Another Query : How can we rename database when it is in use condition .
For renaming database when it is in use condition we can do it in MS _SQL server and in Oracle as Below :
In MS-SQL Server Database by using alter command we can rename a database First we need to go sys or Master database.
Command is as below :
USE MASTER;
GO
ALTER DATABASE DOTC
MODIFY NAME=DOTC1;
GO
In Oracle Database follow the below steps :
First connect as sys user in database command is as below
conn sys/oracle as sysdba
Now you need to find the user id and name for database from user$ table
Select user#,name from user$;
Here you will see all the database name with user ID start from 0 to n
Suppose you will show id 54 for your database you need to modify or rename then use below command.
update user$ set name=dotc1 where user#=54;
Database name will be updated to dotc1.
After this use commit command
commit;
Shutdown the database and startup , or restart database services.
Another Important Query : How can we insert multiple values in One statement in SQL.
Suppose we have table department with employee_id and name column Below SQL statement is used to insert multiple values in table.
Insert into department
(employee_id,name)
Values(100,'Dheeraj'),
(200,'Diksha'),
(300,'Sakshi'),
(400,'Minu');
Below is the output of above query in image :
Here you can see 4 record inserted by using one SQL query , we can insert multiple records in same manner.
Another Query How to Find out the Position of T in word DOTC in MY SQL
We use Locate function to find out specific position of letter in the word. Below is the query for this.
Select LOCATE('T',NAME) as position from department where name='DOTC';
Output will be 3 as position of T in DOTC is at 3rd point.
Below is the output in image for above query.
Please go through all the queries and for reference you can see my SQL blogs for your reference. In next Blog I will come up with more interesting SQL queries which are useful for you.
Thanks.
Comments
Post a Comment