我想从数据库中获取一些数据。从3个表中选择数据
username
从接触表
登录表
email
在两个表tutor
和institute
与2个值检查这是到目前为止我的代码:
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 - 在 '字段列表'
UPDATE
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
你确定用户名字段存在于登录表中吗? – ankurtr 2013-05-03 12:21:10
你确定用户名在研究所和导师表中存在吗? – xQbert 2013-05-03 12:21:46
http://stackoverflow.com/questions/16354226/make-a-select-query-from-two-table-with-where-clause ??? – nvanesch 2013-05-03 12:22:32