SELECT的基本語法如下~ 依照給予的條件,抓出資料。 SELECT * | {[DISTINCT, DISTINCTROW] field_list} FROM table_list WHERE conditions GROUP BY {field_list} [ASC,DESC] HAVING conditions ORDER BY {field_list} [ASC,DESC] 假設有以下表單 student( studno , studname, deptid) 學生資料表 course( yearsemester, courseid, studno , score) 選課單 coursemain( courseid , coursename, coursecredit, courseflag, deptid) 課程基本資料表 teacher( teano , teaname, deptid) 教師資料表 courseopen( yearsemester, courseid , teano, coursetime, room) 教師開課表 dept( deptid , deptname) 科系資料表 1. SELECT * FROM student; 從student表單抓出所有資料 2. SELECT studname FROM student; 從student表單抓出所有學生姓名 3. SELECT DISTINCT studname FROM student; 從student表單抓出所有 不重複 的學生姓名 4. SELECT studname, studno FROM student; 從student表單抓出所有學生姓名、學號 5. SELECT DISTINCTROW studname, studno FROM student; 從student表單抓出所有 不重複列 的學生姓名、學號 DISTINCT與 DISTINCTROW差異是什麼呢? DISTINCT指某欄位不要重複,DISTINCTROW指整個列不要重複。 6. SELECT * FROM student, course; 從student,course表單抓出所有資料 但是以上這個SQL句子其實沒有意義
留言
張貼留言