Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please help me

Author  Topic 

vaseemsidz
Starting Member

3 Posts

Posted - 2008-07-02 : 06:47:27
Im having problem in this scenario where i want to reterive data from the first table with order by date(column). Same is to be done with second table. And finally i need to merge these tables and perform orderby on date coloumns of the both tables.

Something like this,

SELECT XSI_BlogTopics.ItemId AS Expr1, XSI_BlogTopics.CreatedOn, XSI_BlogComments.ItemId AS Expr2, XSI_BlogTopics.CreatedOn AS Expr3
FROM XSI_BlogComments, XSI_BlogTopics
ORDER BY Expr3 DESC, XSI_BlogTopics.CreatedOn DESC

Now this fetches me duplicates rows coz its performing cross join and now im having all the records with order by set. But there are duplicates and i need just first table's itemid which should not duplicate,which in this case gets duplicated.

Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-02 : 06:55:32
is this what you want?
SELECT *
FROM
(
SELECT ItemId, CreatedOn
FROM XSI_BlogComments,
UNION
SELECT ItemId, CreatedOn
FROM XSI_BlogTopics)t

ORDER BY ItemId,CreatedOn
Go to Top of Page

vaseemsidz
Starting Member

3 Posts

Posted - 2008-07-02 : 06:58:50
hi let me check , hold on.
Go to Top of Page

vaseemsidz
Starting Member

3 Posts

Posted - 2008-07-02 : 07:08:26
Cool this brought me records without repetition but , now i just need to filter out the XSI_Comments records. Your query's output was this :

1 2008-06-24 00:00:00.000
2 2008-07-01 10:20:39.110
3 2008-07-01 10:22:05.673
4 2008-07-01 10:22:27.767
5 2008-07-01 10:37:52.907
6 2008-07-02 10:57:59.517
7 2008-07-02 10:58:06.173
8 2008-07-02 10:58:29.453
9 2008-07-02 11:00:47.593
10 2008-07-02 11:00:50.157
11 2008-07-02 11:01:51.157
12 2008-07-02 12:45:48.970
40 2008-06-24 00:00:00.000
41 2008-07-01 00:00:00.000
42 2008-07-02 00:00:00.000

now the last three are what i need , it belongs to XSI_BlogTopics table. how can we reterive that ? Thanks for being quick and helping me out.
Go to Top of Page
   

- Advertisement -