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

Mysql Quries

Uploaded by

pavan kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Mysql Quries

Uploaded by

pavan kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Students data table name

1) select last name from data table name;

2) select name , age, city from data table name where city=’Hyderabad”;

3)select name , age , city from students where age>=23and city=”hyderabad”;

4) select name , age , city from students where city=”hyderabad” or city=”wanaparthy”;

5) select city from students;

6) select distinct city from students; (unic or not repeat again some city name so use distinct);

7) select count(distinct city) from student; (unic or non repeat citys if 25citys there will come number
25)

8) select * from student; (all will come)

9) select * from student limit 0,10 (how many records we want count only not 20 number still)

10)select id ,name,age,city from student order by id desc limit 0,1; (desinding order (last))

11)select max(age) from students; max age will come

12)select min(age) from students; min age will come

13)select avg(age) from students;

14) select sum(age) from students;(if we want total soming in data table we do sum operation)

15) select gender,count(id) from student ;out put male 22

16) select gender,count(id) from student group by gender; out put female=10,male=22

17)select city ,count(id) from students group by city;out put e city lo entha mandhi student vunnaro
total number esthudhi 22 or 25like
18)select name from students where name like “pa%”(pa tho start ayyename and pa tharavath em
vunna data fech avuthundhi)

19) select name from students where name like”%am”; (finishing lo am vunte display avuthundhi)

20) select name from student where name like “%am%”(midile lo amvunte vasthundhi)

21) select * from students where city=”tg”or city=”wanaparthy”;

22) select * from students where city in(“hyd”,”wanaparhty”);( both city students will come)

23) select * from students where city not in(“hyd”,”wanaparhty”); (remaining city out put willcome )

24) select name from students where name not like “ra%”; (remaining city out put willcome )

25) select name, age from students where age between 24 and 30;(here also we usenot like)

26) select * from students where id=2; (we will get id 2 person details)

27) select id,count(adate) as working , count(if (astatus=”p”,null)) as present from attendance group by
id;

Output:

Id working present

1 4 3

2 4 2

3 4 4

28) select count (distinct city) as total from students;(total citys count number will get 6 or 8like)

If I remove count unic city names we will get

29)

Django and sql queries:

Find all name like start name with R and last name should be d

Sql :
SELECT username, first_name, last_name, email FROM auth_user WHERE first_name LIKE 'R%, OR
last_name LIKE 'D%';

Django:

queryset = User.objects.filter( first_name__startswith='R' ) |


User.objects.filter(last_name__startswith='D')

union:

The UNION operator is used to combine the result-set of two or more querysets. The querysets can be
from the same or from different models. When they querysets are from different models, the fields and
their datatypes should match.

You might also like