簡體   English   中英

從兩個表中進行選擇,並按兩個表中公共列的先后順序排列它們

[英]Select from two tables and arrange them in desc order of a common column in the two tables

我有兩個表第一個表(消息表):message_id,參與者ID,時間(默認值:current_timestamp)和message_body。

第二個表(分配表):allocation_id,參與者ID,時間(默認值:current_timestamp),信息。

兩個表中的participant_id相同,如何從兩個表中選擇所有信息,然后以“時間”的降序排列。

例如:從表a中選擇*連接表b,其中join_id = 1 desc(time);

我想要它,以便它將根據時間進行安排。 希望我的信息清楚。 如果您需要更多說明,請隨時聯系我。

假設您要按時間在分配中排序。

Select m.id, a.allocation_id, a.info, m.message_body, a.time, b.time
FROM messages as m
INNER JOIN allocation as a
ON m.participant_id=a.participant_id
ORDER BY a.time DESC;

如果要按消息中的時間排序:

Select m.id, a.allocation_id, a.info, m.message_body, a.time, b.time
FROM messages as m, allocation as a
INNER JOIN allocation as a
ON m.participant_id=a.participant_id
ORDER BY m.time DESC;

嘗試這個:

從表a中選擇*
在a.participant_id = b.participant_id上加入表b
其中a.participant_id = 1
由b.time desc排序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM