mysql left join,这样的query怎么写?

标签 mysql

我有

首先:

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 查询中?

预先感谢您的回答:)

最佳答案

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 的小部件选择子级。

关于mysql left join,这样的query怎么写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1125065/

相关文章:

php - 这个 'paid or unpaid invoices' MySQL 查询可能吗?

php - 向 PHP MYSQL 函数添加 If/else 错误/成功消息

mysql - 我可以在不区分大小写的文件系统上强制 MySql 表名区分大小写吗

php - Mysql 显示所有管理员用户,但不显示已登录的管理员

MySQL:批量插入的自动增量行总是具有相邻的ID吗?

mysql - 我不断收到错误 : There is already an object named fk_driver_id and i'm not sure how to fix this error. 帮助:(

mysql - 尝试在 ubuntu 14.04 上安装 innodb memcached 插件 MySQL5.6.17

PHP如何将BLOB数据放入数组

mysql - 按值分组,也可以在其他行中找到

php - 一个循环访问两个不同的表