简体   繁体   中英

PHP+Mysql Order By Date For Multiple Table ( Via Left Join )

I have 2 table ( user and product )

I want order rows via date for this tables

user table :

在此处输入图片说明

product table :

在此处输入图片说明

My Code :

"SELECT *,product.* FROM `user` LEFT JOIN `product` ORDER BY `?`";

I want result it :

Four

One

Three

Two

It appears that you really want to do a UNION query between the user and product tables. You can then SELECT the Title from this result and order using the Date .

SELECT t.Title
FROM
(
    SELECT Date FROM user
    UNION
    SELECT Date FROM product
) t
ORDER BY t.Date DESC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM