PHP query for SQL Server 2008 issues

Source: Internet
Author: User
I want PHP paging to get data from SQL Server 2008,

1. mysql can limit n,m, SQL Server does not
2. To get the data of union after the page, see the useful rownum and top on the net, how to combine with union to realize it?


My result set is similar to

(select A,b,c,d from T1) union (select "As A, b,c,d from  T2")  Union (select A,b,c,d from T3)


Want to limit which bar of a result set is returned each time


Reply to discussion (solution)

Write this:

$sql = ' Your SQL query instruction '; $start = 1; Starting offset $pagesize = 20; Number of rows per page $sqls =<<< Sqlselect * FROM (SELECT a.*, ROWNUM RN from ($sql) A where ROWNUM < $start + $pagesize) where R N >= $startSQL;
$sqls is the final execution of the query statement

Understand, the original problem is that I do not know the results of the Union to take an individual name, thank you moderator ~ ~

Finally combined with Baidu I wrote this

SELECT * FROM (     select  *, Row_number () Up (ORDER by A DESC) as RN          from  ($sql) as  S1) as S2  where RN between $from and $to
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.