SQL select *来自教师,除了teacherID = teacher

时间:2014-05-05 14:29:45

标签: mysql sql

我想从表中选择除一行之外的所有值数据。我该怎么做?

table = teachers
headers = TeacherID, Password, FirstName, Surname
TeacherID = teacher

当我尝试

SELECT * 
FROM teachers 
EXCEPT 
SELECT * 
FROM teachers 
WHERE TeacherID = 'teacher'

我收到错误

  

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM teachers WHERE TeacherID = teacher LIMIT 0, 30' at line 1

2 个答案:

答案 0 :(得分:0)

这将选择列TeacherID不包含值teacher

的所有行
Select * from teachers where TeacherID != 'teacher' 

我不确定您的列TeacherID是否为字符串,如果是,请不要将其命名为ID。 ID通常是int数据类型。

如果要选择列TeacherID包含值teacher的所有记录,请执行此操作

SELECT * 
FROM teachers 
WHERE TeacherID = 'teacher'

答案 1 :(得分:0)

你应该

select * from teachers where TeacherID != 'teacher'

OR

select * from teachers where TeacherID not in ('teacher','teacher1','teacher2')