如何在此sql查询中使用0-20之间的范围?

  $sql = 'SELECT * FROM t1
          LEFT JOIN t2 ON t2.wid = t1.wid
          UNION
          SELECT * FROM t1
          RIGHT JOIN t2 ON t2.wid = t1.wid
          limit 0, 20';
  $result = db_query($sql);//->fetchField();

最佳答案

将LIMIT传递到您的查询中。每次您的限额都会变化

$sql = 'SELECT * FROM (SELECT * FROM t1
          LEFT JOIN t2 ON t2.wid = t1.wid
          UNION
          SELECT * FROM t1
          RIGHT JOIN t2 ON t2.wid = t1.wid) AS A LIMIT'.$start.','.$end

10-08 11:07