douxuzui4590 2016-08-25 14:13
浏览 13

合并2从没有关系的2表中选择

I'm making a search engine in php and i use Mysql . I'm trying to search into 2 different kind of tables.A blog table and categories table.

I can't use UNION because tables doesn't have the same number of columns.

SELECT titre, description,url,'actualites' AS type 
FROM cs_actualites 
WHERE cs_actualites.description LIKE :pattern
OR cs_actualites.titre LIKE  :pattern

SELECT
root.url           rootUrl,
parent.url         parentUrl,
child.url          childUrl,
parent.titre       parentTitle,
parent.description parentDesc,
child.titre        childTitle,
child.description  childDesc
FROM cs_categories root
LEFT JOIN cs_categories parent
 ON root.id = parent.parent
LEFT JOIN cs_categories child
 ON parent.id = child.parent
WHERE (root.description LIKE :pattern OR root.titre LIKE :pattern)
  OR (parent.titre LIKE :pattern OR parent.description LIKE :pattern)
  OR (child.titre LIKE :pattern OR child.description LIKE :pattern);

The both queries should results : a title , a description and an url. The 2nd query should results addionnaly many urls(for each category and sub_category).

How can i get result from those 2 queries into one ?

Thank you for helping :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度