我正在尝试从 db 获取一些数据。
username
从登录表email
从联系表
检查两个表中的 2 个值tutor
和institute
到目前为止,这是我的代码:
SELECT s. * , c.email, l.username
FROM (
SELECT contact_id AS id,
login_id,
username,
tutor_code AS code,
tutor_name AS Name,
'tutor' AS profile
FROM tutors
WHERE tutor_code = $code AND tutor_name = '$name'
UNION ALL
SELECT contact_id AS id,
login_id,
username,
institute_code AS code,
institute_name AS Name,
'institute' AS profile
FROM institutes
WHERE institute_code = $code AND institute_name = '$name'
)
INNER JOIN contact c ON s.id = c.contact_id
INNER JOIN login l ON s.login_id = l.login_id
此查询不起作用,并且有一条错误消息。
1054 - “字段列表”中的未知列“用户名”
更新
SELECT s. * , c.email, l.username
FROM (
SELECT contact_id AS id,
login_id,
username,
tutor_code AS code,
tutor_name AS Name,
'tutor' AS profile
FROM tutors
WHERE tutor_code = $code AND tutor_name = '$name'
UNION ALL
SELECT contact_id AS id,
login_id,
username,
institute_code AS code,
institute_name AS Name,
'institute' AS profile
FROM institutes
WHERE institute_code = $code AND institute_name = '$name'
)s
INNER JOIN contact c ON s.id = c.contact_id
INNER JOIN login l ON s.login_id = l.login_id