SELECT student.*, degree.*, field.*, academic_year.*, term.*, story.story FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term WHERE (((story.story)='สมัครพร้อมลงทะเบียน')) WHERE story.id_story NOT IN (SELECT id_story FROM story WHERE story='ลงทะเบียนเรียน')
มันเออเรอร์ว่า:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression '(((story.story)='สมัครพร้อมลงทะเบียน')) WHERE story.id_story NOT IN (SELECT story FROM story WHERE story='ลงทะเบียนเรียน')'.
ที่ผมใช้ NOT IN เพราะว่าต้องการหาคนที่ไม่มาลงทะเบียนน่ะครับ......
SELECT student.*, degree.*, field.*, academic_year.*, term.*, story.story
FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term
WHERE (((story.story)='สมัครพร้อมลงทะเบียน')) WHERE story.id_story NOT IN (SELECT id_story FROM story WHERE story='ลงทะเบียนเรียน')
WHERE ซ้อน WHERE ไม่ได้ครับ
SELECT student.*, degree.*, field.*, academic_year.*, term.*, story.story
FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term
WHERE story.story = 'สมัครพร้อมลงทะเบียน' AND story.id_story NOT IN (SELECT id_story FROM story WHERE story='ลงทะเบียนเรียน')
ช่วยผมอีกทีนะ
SELECT id_student,student_code,firstname,lastname,degree,field,academic_year,term,story From (SELECT student.*, degree.degree, field.field, academic_year.academic_year, term.term, story.story FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term WHERE (((story.story)='สมัครพร้อมลงทะเบียน'))) WHERE id_student NOT IN (SELECT id_student,student_code,firstname,lastname,degree,field,academic_year,term,story From (SELECT student.*, degree.degree, field.field, academic_year.academic_year, term.term, story.story FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term WHERE (((story.story)='ลงทะเบียนเรียน'))))
มันเออเรอร์ว่า:
Microsoft JET Database Engine (0x80004005)
You have written a subquery that can return more than one field without using the EXISTS reserved word in the main query's FROM clause. Revise the SELECT statement of the subquery to request only one field.[font=Verdana color=red][/font]
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='tbl1') DROP TABLE tbl1
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='tbl2') DROP TABLE tbl2
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='tbl3') DROP TABLE tbl3
SELECT student.*, degree.degree, field.field, academic_year.academic_year, term.term, story.story
INTO tbl1
FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term
WHERE tbl1.story = 'ลงทะเบียนเรียน'
SELECT id_student,student_code,firstname,lastname,degree,field,academic_year,term,story
INTO tbl2
FROM tbl1
SELECT student.*, degree.degree, field.field, academic_year.academic_year, term.term, story.story
INTO tbl3
FROM ((((student INNER JOIN degree ON student.id_student = degree.id_student) INNER JOIN field ON degree.id_degree = field.id_degree) INNER JOIN academic_year ON field.id_field = academic_year.id_field) INNER JOIN term ON academic_year.id_academic_year = term.id_academic_year) INNER JOIN story ON term.id_term = story.id_term
WHERE (((story.story)='สมัครพร้อมลงทะเบียน'))
SELECT tbl3.id_student,tbl3.student_code,tbl3.firstname,tbl3.lastname,tbl3.degree,tbl3.field,tbl3.academic_year,tbl3.term,tbl3.story
FROM tbl2, tbl3
WHERE tbl2.id_student != tbl3.id_student