简体   繁体   English

如何按MySQL中不同表的两个日期字段之间的最新更新日期排序

[英]How to order by latest updated date between two date fields from different tables in MySQL

I have two tables CUSTOMERS and QUERIES.. I want to display the result such that if new customer is added to CUSTOMER table or new query is added to QUERY table then which one is added recently among them should be ordered first.. I have tried query like this, 我有两个表CUSTOMERS和QUERIES ..我想显示结果,以便如果将新客户添加到CUSTOMER表或将新查询添加到QUERY表,那么应该首先订购最近在其中添加的一个表。这样的查询,

SELECT c.name, q.query FROM CUSTOMER c, QUERY q 
WHERE c.id=q.cust_id 
ORDER BY c.added_date DESC, q.added_date DESC;

But it is not showing proper result.. Plz help.. 但这并没有显示出正确的结果。

It should be the following: 应该是以下内容:

order by greatest(c.added_date,q.added_date) desc

This works in postgres and other DBMSs - hopefully works the same for mysql and oracle. 这适用于postgres和其他DBMS-希望适用于mysql和oracle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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