0

我希望这两个 SELECT 查询给出一个结果,然后我想按date_time

选择 1:

"SELECT * FROM `table` WHERE `f_id` = '$uid' AND `t_id` = '$pid'"

选择 2:

"SELECT * FROM `table` WHERE `f_id` = '$pid' AND `t_id` = '$uid'"

我试图将它放在一个 WHERE 子句中,但这是不可能的,我也尝试将它们放在子查询中,但这使得 SELECT 2 加入正确的 SELECT 1 :/ 我想要这两个查询的一个输出数组,按date_time. 这怎么可能?

4

3 回答 3

5
SELECT * FROM `table` WHERE `f_id` = '$uid' AND `t_id` = '$pid'
UNION ALL
SELECT * FROM `table` WHERE `f_id` = '$pid' AND `t_id` = '$uid'

编辑:

呃……对不起,我没看到是同一张桌子。

SELECT * FROM table
  WHERE (`f_id` = '$uid' AND `t_id` = '$pid') OR (`f_id` = '$pid' AND `t_id` = '$uid')
  ORDER BY date_time
于 2013-03-24T20:34:59.860 回答
3

关于什么:

SELECT 
    * 
FROM 
    `table` 
WHERE 
    (`f_id` = '$uid' AND `t_id` = '$pid') OR 
    (`f_id` = '$pid' AND `t_id` = '$uid')
ORDER BY 
    `date_time` DESC
于 2013-03-24T20:36:35.207 回答
0

尝试这个

   SELECT * FROM 

      ( select * FROM `table` WHERE `f_id` = '$uid' AND `t_id` = '$pid'
       union all 
        SELECT * FROM `table` WHERE `f_id` = '$pid' AND `t_id` = '$uid' )t

   ORDER BY date_time
于 2013-03-24T20:39:40.210 回答