試試這個它會工作:
$q = "SELECT keyword, col, city_name, image_name, tutor_code
FROM (
SELECT tutor_name AS keyword, 'Tutors' AS col, IFNULL(c1.city_name, '') city_name, IFNULL(ti.image_name, '') image_name, tutor_code FROM tutors AS t
LEFT JOIN address a ON t.address_id = a.address_id
LEFT JOIN city c1 ON a.city_id = c1.city_id
LEFT JOIN tutor_images ti ON t.tutor_id = ti.tutor_id and ti.image_type = 'profile'
UNION
SELECT subjects AS keyword, 'Subject' AS col, '' city_name, '' image_name, '' tutor_code FROM subject
UNION
SELECT city_name AS keyword, 'City' AS col, '' city_name, '' image_name, '' tutor_code FROM city
UNION
SELECT institute_name AS keyword, 'Institute' AS col, '' city_name, '' image_name, '' tutor_code FROM institutes
) s
WHERE keyword LIKE '%$queryString%'
LIMIT 10";
你嘗試過什麼?我們不在這裏做你的工作;)。但我想你想要'JOIN'命令。 – looper
指定要顯示的列和使用JOIN執行相同的操作 –
閱讀本文可能會有助於http://www.w3schools.com/sql/sql_join.asp – xurca