select از پرکاربرد ترین دستورات سکوال می تونه باش دلیل عمدش هم اینه که شاید تنها دستوریه که می شه باهاش مقادیری رو از جداول پایگاه داده رو نمایش میده
دستور کلیش به این صورت هستش
SELECT [ALL | DISTINCT] column1[,column2] FROM table1[,table2] [WHERE "conditions"] [GROUP BY "column-list"] [HAVING "conditions] [ORDER BY "column-list" [ASC | DESC] ]
درسته که یه خورده گیج کننده است ولی با مثال روشن تر میشه البته نکته ای که اینجا باید توجه داشته باشید بهش اینه و دلیلی که کد فوق اینقدر شلوغ شده که رسما شتر با بارش گم میشه این می تونه باشه که سعی شده تمامی دستوراتی که تو بدنه ی select در شرایط مختلف به کار برده میشه رو نمایش بده
select from student
where age>10;
select from student
where age =16 and Lname=torabi;
من در ادامه مثال هایی رو می نویسم که به عنوان نمونه ای از select با به کاربردن دستورات دیگه در متن دستور نوشته شدن البته به تفضیل تو پست های اینده در مورد تمامی این دستوراتی که تو متن select می تونن بیان حرف میزنیم ولی اگه بازم مشکلی بود در خدمتیم
-----------------------------------------
1
selcet sname from student
where student.major='softwer';
----------
2 select sname,major from student,studentCours
where student.id=studetCourses.sid
and studentCourses.grade<10
----------
3 select sname from student,studentcorses
where student.id=studentcorses.sid and
studenCorses.term=1 and
studentCorses.yryr='85-86' and
grade<10
----------
4 select Ctitle from studenCorses,Corses
where studentCorses.cid=Corses.id
and Corses.Cunit=3 and
studentCorses.grade<10;
----------
5 select sname from student,studentcorse,corse
where studenCorse.id=student.sid and Corses.id=Student.cid
and Corses
-----------
6 select Max(grade),cid from studentCourses
group by Cid;
-------------------------------------
7 select avg(grade),cid,yryr from studentCourses
froup by cid,yryr;
-----------------------
8 select min(grade),max(grade) from studentCorses,student
where student.sid=studentcorses.id and
student.sname='';
-----------------
9 select sname from student,studentcourses where
student.sid=studentCourses.idrm=''
and stdentCurses.yryr=''
studentCourses.te
studentCourses.grad is Null
------------------------
10 select Ctitle,grade from studentCourses,Courses
where StudentCourses.cid=Courses.id
and StudentCourses.grade is Not null;
------------------
11 select sname from student,studetCourses, Corses
where studentCourses.id=Student.sid and
studentCourses.cid=Courses.id and
Courses.Ctype=''
StudentCourses.grade>10
--------------
12 select Count(*),major from student
group bye major
--------------
13 select Ctitle from Courses,studentCourses
where StudentCourses.cid=Courses.id
and StudentCourses.yryr='85-86'
and StudentCourses.term='1' and
grup by Ctitle having Count(*)<10;
-------------
14 select grade,count(*) from Courses,studentCourses
where Courses.id=stuntCourses.cid
and studentCourses.term='1' and
studentCourses.yryr='85-86' and
Curses.Ctitle='databace'
grup bye grade
--------------
15 select * from student where City=''
select * from student where maior=''
--------------
16 select * from student,studentCurses
where student.sid=studentCourses.id and
student.city=''
studentCourses.grade>11;
------------------
17 select * from student,studentCourses
student.sid=studentCourses.id
studentCourses.grade>15; and
student.major=''
--------------------
18 select * from student,studentCourses where
dtudent.sid=studentCourses.id
and studentCourses.gradeom student>17 or student.major='';
------------------
19 select * from student,studentcorses where
studentCourses.id=student.sid
(studentCourses.grade>17
and student.major='')
or ......
--------------------
20 select Snam from student where city like t%;
--------------------
21 select * from student where city like '%S%';
----------------------------------------
22 SELECT * FROM STUDENT
where major='' and
order by sname;
------------------------
23 select * from studetnt where citi in ('','');
----------------
24 select select avg(grade) from student,studentCourses,corses
where student.sid=studentCourses.id and
studentCourses.cid=corses.id
and student.major='' and
Courses.ctitle='';
---------------
25 select Corses.Ctilel from student,studcorses,corses
student.sid=studentCourses.id and
corses.id=studentCourses.cid andstudent.sname='' and
------------------
27 select sname ,from student
where major(select major from studet where Snam e='');