How to replace OR operator with UNION operator?

前端 未结 3 2086
孤街浪徒
孤街浪徒 2021-01-22 12:02

Here is my query:

SELECT 
    h.id,
    h.subject,
    h.body matnF,
    h.amount,
    h.keywords tags,
    h.closed,
    h.author_id author,
    h.AcceptedAnswe         


        
3条回答
  •  半阙折子戏
    2021-01-22 12:57

    The first thing I would try is a subquery:

    from ((select q.* from quanda q where q.id = :id1) union
          (select q.* from quanda q where q.related = :id2)
         ) left join
         . . .
    

    Note: This really wants indexes on quanda(id) and quanda(related) for performance.

    If few rows are selected, then this might be much faster.

提交回复
热议问题