私は次のデータベース構造を持っています(メッセージング用):
id from_userid to_userid time_stamp message
私はID 1のユーザーで、対話しているすべてのuser_idのリストをタイムスタンプでソートして取得したいとしましょう-それを行う方法はありますか?
ありがとう
私は次のデータベース構造を持っています(メッセージング用):
id from_userid to_userid time_stamp message
私はID 1のユーザーで、対話しているすべてのuser_idのリストをタイムスタンプでソートして取得したいとしましょう-それを行う方法はありますか?
ありがとう
もしかして、こういうこと?
SELECT *
FROM (
SELECT from_id AS id, time_stamp
FROM <table>
WHERE to_id=<user id>
UNION
SELECT to_id AS id, time_stamp
FROM <table>
WHERE from_id=<user id>
) AS t
ORDER BY time_stamp
SELECT *
FROM your_table
WHERE from_userid = 1 OR to_userid = 1
ORDER by time_stamp