如何将2个具有INNER JOIN的SELECT组合在一起?

Use PHP and MySQL and have 2 SELECT statements to combine together

$sql="SELECT DISTINCT t1.* 
      FROM entry  AS t1
      INNER JOIN entry_tag AS t2 ON t1.entry_id=t2.entry_id
      INNER JOIN tag AS t3 ON t3.tag_id=t2.tag_id 
      WHERE t1.title LIKE '%$key%' OR
      t1.content LIKE '%$key%' OR
      t3.tag LIKE '%$key%'  AND t1.status='OK'
      ORDER BY view  DESC";

$sql="SELECT DISTINCT t1.* 
      FROM entry  AS t1
      INNER JOIN candidate AS t2 ON t1.entry_id=t2.entry_id 
      WHERE t2.name LIKE '%$key%' AND t1.status='OK'
      ORDER BY view  DESC"; 

How to combine these 2 SELECTs into 1?

Use UNION ALL:

  $sql="SELECT DISTINCT t1.* 
    FROM entry  AS t1
    INNER JOIN entry_tag AS t2 ON t1.entry_id=t2.entry_id
    INNER JOIN tag AS t3 ON t3.tag_id=t2.tag_id 
    WHERE t1.title LIKE '%$key%' OR
    t1.content LIKE '%$key%' OR
    t3.tag LIKE '%$key%'  AND t1.status='OK'
  UNION ALL
    SELECT DISTINCT t1.* 
    FROM entry  AS t1
    INNER JOIN candidate AS t2 ON t1.entry_id=t2.entry_id 
    WHERE t2.name LIKE '%$key%' AND t1.status='OK'
    ORDER BY view  DESC";
select * from
(SELECT DISTINCT t1.* 
  FROM entry  AS t1
  INNER JOIN entry_tag AS t2 ON t1.entry_id=t2.entry_id
  INNER JOIN tag AS t3 ON t3.tag_id=t2.tag_id 
  WHERE t1.title LIKE '%$key%' OR
  t1.content LIKE '%$key%' OR
  t3.tag LIKE '%$key%'  AND t1.status='OK'
  ORDER BY view  DESC")
union all
("SELECT DISTINCT t1.* 
  FROM entry  AS t1
  INNER JOIN candidate AS t2 ON t1.entry_id=t2.entry_id 
  WHERE t2.name LIKE '%$key%' AND t1.status='OK'
  ORDER BY view  DESC")