选择行时不需要的行

时间:2016-01-03 06:54:35

标签: mysql sql select

以下SELECT查询无法正常运行:

SELECT DISTINCT
    student.firstname,
    student.lastname,
    student.emailAddress,
    cast(memberslist.dateJoined as DATE) as dateJoined
FROM student, memberslist
WHERE 
    memberslist.orgName = 'Elite League of Information Technology Students'
    AND memberslist.joined = 'yes'

我有2个表:studentmemberslist

memberslist表:
memberslist table

student表:
student table

当我运行查询时,结果如下:

SQL query results

我不明白为什么当pakalu是精英信息技术联盟的学生'

时,它给了我WHERE

1 个答案:

答案 0 :(得分:3)

不鼓励使用隐式连接,您需要以下查询:

SELECT s.firstname, s.lastname, s.emailAddress, cast(m.dateJoined as DATE) as dateJoined 
FROM student s INNER JOIN memberslist m
ON s.emailAddress = m.emailAddress
WHERE m.orgName = 'Elite League of Information Technology Students' 
  AND m.joined = 'yes'