MySQL

Snigdha
Snigdha
Aug 31, 2018 · 2 min read
  1. How can we show databases in SQL?

Ans. There is an answer in the question itself…..Yes!!

 show databases;

2. How can we show tables?

Ans. Again, the answer is in the question itself,

show tables use database_name;Ex. —
show tables use student; — here student is my database_name.

3. How to show columns in a table?

Ans. show columns from table_name;

For example : create an employee table as table name Employee :

Fig a : Employee table
show columns from Employee;Dept_nameEmp_nameSalary

4. Fetch three highest salaried employees from Employee table?

select salary,emp_name from employee group by emp_name order by salary desc limit 3;

Remember sql is not a case sensitive.

and in

  • MySQL : we use limit
Syntax : 
select col_name(s) from table_name where condition limit number;
  • Sql server : we use TOP
Syntax : select TOP number/percent col_name from table_name where condition;
  • Oracle : we use ROWNUM≤number;
Syntax : select col_name(s) from table_name where ROWNUM ≤ number;

5. Fetch three least salaried employees?

Ans. Similarly we need to fetch in ascending order(by default sql will fetch in asc) rather than in desc.

select emp_name,salary from employee group by emp_name order by salary limit 3;

6. Fetch department wise highest salary from employee table?

select dept_name,,max(salary) from employee group by dept_name order by salary desc;

7. To remove duplicate values from the table, we use distinct command.

select distinct * from employee;

8. SQL Query order of operations

Ans.

1.from and Join’s

2. where

3. group by

4. having

5. select

6. distinct

7. order by

8. limit

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade