我有
第一
select url from urls where site = '$value' order by url
第二
select id, widget_name from widgets where display_urls LIKE 'urls.url' and is_father=1 order by id
第三
select id, widget_name from widgets where display_urls RLIKE 'urls.url' and is_father=0 order by id
第四:
select id, widget_name, father_widget from widgets where father_widget = 'widgets.id' order by id
第四个查询必须只从第二个查询中获取widgets.id 第二个和第三个查询从第一个查询中获取urls.url的值
如何使用左连接在一个mysql查询中编写所有这些?
提前感谢您的回答:)
答案 0 :(得分:1)
SELECT w.id, w.widget_name, c.*
FROM urls
JOIN widgets w
ON w.display_urls LIKE urls.url
OR w.display_urls RLIKE urls.url
LEFT JOIN
widgets с
ON c.father_widget = w.id
AND w.display_urls LIKE urls.url
AND w.display_urls NOT RLIKE urls.url
WHERE site = $value
ORDER BY
url
这将仅为那些LIKE
但RLIKE
url
{{1}}小部件的小部件选择子项。