Author |
Topic |
futchi
Starting Member
1 Post |
Posted - 2010-11-14 : 15:21:54
|
i am paging resolts of SELECT tbl_users.userName and tbl_thoughts.thought. i'm tring to get 6 users by page, and 2 thoughts of every user by page. the SELECT queries work separatly ! but tring to UNION them causes "syntex erorr neer UNION statment". what am i doing wrong?SELECT * FROM (SELECT TOP 6 * FROM (SELECT TOP 6 userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID=1 ORDER BY userID ASC) AS T1 ORDER BY userID DESC) AS TA1 ORDER BY userID ASC UNION ALLSELECT * FROM (SELECT TOP 6 * FROM (SELECT TOP 6 userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID=2 ORDER BY userID ASC) AS T2 ORDER BY userID DESC) AS TA2 ORDER BY userID ASC";(i'm using using sql server 2008) |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-15 : 05:21:57
|
select userName,thought from(SELECT TOP 6 1 as sorder,userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID =1union allSELECT TOP 6 2 as sorder,userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID =1) as tORDER BY sorder,userID ASCMadhivananFailing to plan is Planning to fail |
|
|
TimSman
Posting Yak Master
127 Posts |
Posted - 2010-11-15 : 08:48:30
|
[url]http://www.asp101.com/articles/gal/effectivepaging/default.asp[/url]I had to do paging for a gridview once, because it was just too slow to use the built-in functionality.The above link gives you some idea of how to implement it. |
|
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-16 : 03:08:21
|
select userName,thought from(SELECT TOP 6 1 as sorder,userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID =1 order by userid) as tunion allselect userName,thought from(SELECT TOP 6 1 as sorder,userName,thought FROM tbl_thoughts INNER JOIN tbl_users ON thoughtUserID = userID WHERE userID =2 order by userid) as tMadhivananFailing to plan is Planning to fail |
|
|
|