简体   繁体   中英

unknown column in where clause in sql

SELECT * 
FROM subjects 
INNER JOIN entries ON entries.subject_id= subjects.subject_id 
INNER JOIN students ON entries.student_id=students.student_id 
WHERE subjects.exam_board LIKE ‘OCR’;

when i execute this the error unknown column 'OCR' in where clause

The following is my subject table

INSERT INTO subjects 
(subject_id, subject_name, level_of_entry, exam_board) 
VALUES 
(1, 'chemistry', 'AS', 'OCR'); 
INSERT INTO subjects 
(subject_id, subject_name, level_of_entry, exam_board) 
VALUES 
(2, 'biology', 'GCSE', 'AQA');
INSERT INTO subjects
(subject_id, subject_name, level_of_entry, exam_board) 
VALUES 
(3, 'music', 'GCSE', 'Edexcel'); 

the below is my students table

 INSERT INTO students 
 (student_id,first_name,middle_name,last_name,email,password,reg_date) 
 VALUES 
 (NULL, 'Tom', 'Michael', 'ford',  'tom@yahoo.com','tom1234','2003/12/08');
 INSERT INTO students 
 (student_id,first_name, middle_name, last_name, email, password, reg_date)
 VALUES 
 (NULL, 'michael', 'scoffield', 'burrows',  'lincoln@yahoo.com', 'lincoln1234', '2001/12/16');

You have to use '(single quote) sign insted of ` in like clause hope below code will help you

SELECT * 
FROM subjects 
INNER JOIN entries ON entries.subject_id= subjects.subject_id 
INNER JOIN students ON entries.student_id=students.student_id 
WHERE subjects.exam_board LIKE 'OCR';
SELECT * 
FROM subjects 
INNER JOIN entries ON entries.subject_id= subjects.subject_id 
INNER JOIN students ON entries.student_id=students.student_id 
WHERE subjects.exam_board LIKE 'OCR';

Your using the wrong type of quote.

You may also want to update your LIKE to be

WHERE subjects.exam_board LIKE 'OCR%';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM