2011-04-07 152 views
-2
$query_index_neighborhood1 = 
"SELECT areas_db.areas_name, areas_db.areas_id, neighborhoods_db.neighborhoods_id, 
neighborhoods_db.neighborhoods_name, neighborhoods_db.neighborhoods_area_id, 
areas_db.areas_state_id 
FROM (
     (
     (
      restaurants_db 
      INNER JOIN neighborhoods_db ON neighborhoods_db.neighborhoods_id=restaurants_db.restaurants_neighborhood 
     ) 
     INNER JOIN areas_db ON areas_db.areas_id=neighborhoods_db.neighborhoods_area_id 
     ) 
     INNER JOIN areas_db AS areas_db1 on areas_db1.areas_id=restaurants_db.restaurants_area 
    ) 
WHERE areas_db.areas_state_id=$mxstateid 
GROUP BY neighborhoods_db.neighborhoods_id 
ORDER BY areas_db.areas_id, neighborhoods_db.neighborhoods_name ASC"; 
+2

究竟是什麼問題? – webdad3 2011-04-07 15:22:01

+2

可能希望粘貼您的'create table'語句,以便人們可以看到您已經獲得的索引,以及可能對查詢的描述。沒有機構可以幫你解決所有的問題 – dogmatic69 2011-04-07 15:22:22

+1

你的桌子上有什麼索引? – 2011-04-07 15:23:39

回答

0

作爲一個有趣的想法鍛鍊,我想出了以下內容:

SELECT a.areas_name, 
    a.areas_id, 
    n.neighborhoods_id, 
    n.neighborhoods_name, 
    n.neighborhoods_area_id, 
    a.areas_state_id 
FROM neighborhoods_db AS n 
INNER JOIN areas_db AS a ON a.areas_id = n.neighborhoods_area_id 
WHERE a.areas_state_id = $mxstateid 
    AND n.neighborhoods_id in (SELECT restaurants_neighborhood FROM restaurants_db) 
ORDER BY a.areas_id, n.neighborhoods_name ASC 

另外,表的別名是你的朋友。