SQ L Basic Queries
SQ L Basic Queries
Q1. Write a query to fetch the EmpFname from the EmployeeInfo table
in upper case and use the ALIAS name as EmpName.
1 SELECT UPPER(EmpFname) AS EmpName FROM EmployeeInfo;
Q2. Write a query to fetch the number of employees working in the
department ‘HR’.
1 SELECT COUNT(*) FROM EmployeeInfo WHERE Department = 'HR';
Q3. Write a query to get the current date.
You can write a query as follows in SQL Server:
1 SELECT GETDATE();
You can write a query as follows in MySQL:
1 SELECT SYSTDATE();
Q4. Write a query to retrieve the first four characters of EmpLname
from the EmployeeInfo table.
1 SELECT SUBSTRING(EmpLname, 1, 4) FROM EmployeeInfo;
Q5. Write a query to fetch only the place name(string before brackets)
from the Address column of EmployeeInfo table.
Using the MID function in MySQL
1 SELECT MID(Address, 0, LOCATE('(',Address)) FROM EmployeeInfo;
Using SUBSTRING
1 SELECT SUBSTRING(Address, 1, CHARINDEX('(',Address)) FROM EmployeeInfo;
Q6. Write a query to create a new table which consists of data and
structure copied from the other table.
Using the SELECT INTO command:
Databases Training