0% found this document useful (0 votes)
4 views

Mysql Basic Notes-2

The document contains a series of SQL queries for managing and retrieving data from a 'students' table. It includes commands for inserting records, selecting specific fields, applying filters, counting unique values, and using wildcards for pattern matching. Additionally, it demonstrates how to aggregate data and limit the number of records returned in queries.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Mysql Basic Notes-2

The document contains a series of SQL queries for managing and retrieving data from a 'students' table. It includes commands for inserting records, selecting specific fields, applying filters, counting unique values, and using wildcards for pattern matching. Additionally, it demonstrates how to aggregate data and limit the number of records returned in queries.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

SELECT- QUERIES

1. insert into students(name,age,gender,city,contact) values


('Agneeshwar',19,'m','Salem','9876543210'),
('Akash',22,'m','Namakkal','9876543210'),
('Arun',25,'m','Hosur','9876543210'),
('Ashok Kumar',20,'m','Salem','9876543210'),
('Asma Ahamed',18,'f','Namakkal','9876543210'),
('Harini',21,'f','Hosur','9876543210'),
('JayaShree',19,'f','Salem','9876543210'),
('Jessy',19,'f','Salem','9876543210'),
('Mohith',22,'m','Namakkal','9876543210'),
('Monesh Sai',24,'m','Hosur','9876543210'),
('Muthu Sri Sruthika',19,'f','Salem','9876543210'),
('Nithish',23,'m','Namakkal','9876543210'),
('Pratheesh',24,'m','Hosur','9876543210'),
('Ravi Varma',20,'m','Salem','9876543210'),
('Rithick',22,'m','Namakkal','9876543210'),
('Rithick Rosan',18,'m','Hosur','9876543210'),
('Roshini',21,'f','Salem','9876543210'),
('Sabari',23,'m','Namakkal','9876543210'),
('Sarnesh',21,'m','Hosur','9876543210'),
('Sibi Shree',22,'f','Salem','9876543210'),
('Supriya',19,'f','Namakkal','9876543210'),
('Tharika',21,'f','Hosur','9876543210'),
('valtina',20,'f','Salem','9876543210'),
('Yashwanth',23,'m','Hosur','9876543210');

2. select *from students;


Select particular fields in a table?
3. SELECT name,age FROM students;

Select records with criteria?


4. SELECT name,age,city FROM students WHERE city='Hosur';

Select records with multiple criteria’s?


5. SELECT name,age,city FROM students WHERE city='Hosur' AND age >= 23;
6. SELECT name,age,city FROM students WHERE city='Namakkal' OR city='Hosur';

7. SELECT name,age,city FROM students WHERE (city='Namakkal' OR city='Hosur') AND age >=
23;

To select unique values in a fields?


8. select city from students;

9. SELECT DISTINCT city FROM students;

To count unique values in a field?


10. SELECT COUNT(DISTINCT city) FROM students;
To count unique values in a field with allies name?
11. SELECT COUNT(DISTINCT city) AS Number_of_Cities FROM students;

To display N-Number of records while view all records in a table?


12. SELECT * FROM students LIMIT 5;

To Select a range of records ( ex: 5,7) here from 5th records to 7 no of records ?
13. SELECT * FROM students LIMIT 5,7;

To select the very first record from a table?

14. SELECT * FROM students LIMIT 0,1;

To select the very first record from a table?

15. SELECT * FROM students ORDER BY id DESC LIMIT 0,1;


To select maximum value in a table?
16. SELECT MAX(age) FROM students;

To select minimum value in a table?

17. SELECT MIN(age) FROM students;

To select average of a field?

18. SELECT AVG(age) FROM students;

To round a float value?

19. SELECT ROUND(AVG(age),0) FROM students;

To select sum of a field?

20. SELECT SUM(age) FROM students;

To count male and female records ?

21. select count(gender) from students;

To select group wise records?

22. SELECT gender,COUNT(gender) As Total FROM students GROUP BY gender;


WILD CARD QUERIES

To select values starts with some letters?

1. SELECT NAME FROM students WHERE name LIKE 'Ra%';

To select values ends with some letters?

2. SELECT NAME FROM students WHERE name LIKE '%ee';

To select values contains some letter?

3. SELECT NAME FROM students WHERE name LIKE '%hi%';

To select values having given keywords?

4. SELECT * FROM STUDENTS WHERE city IN('Salem','Namakkal');


To select values not having given keywords?

5. SELECT * FROM STUDENTS WHERE city NOT IN('Salem','Namakkal');

To select values using between keyword?

6. SELECT name, age FROM students WHERE age BETWEEN 24 AND 30;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy