我想從數據庫中獲取一些數據。從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