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.
| 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 Expr3FROM XSI_BlogComments, XSI_BlogTopics ORDER BY Expr3 DESC, XSI_BlogTopics.CreatedOn DESCNow 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, CreatedOnFROM XSI_BlogTopics)t ORDER BY ItemId,CreatedOn |
 |
|
|
vaseemsidz
Starting Member
3 Posts |
Posted - 2008-07-02 : 06:58:50
|
| hi let me check , hold on. |
 |
|
|
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.0002 2008-07-01 10:20:39.1103 2008-07-01 10:22:05.6734 2008-07-01 10:22:27.7675 2008-07-01 10:37:52.9076 2008-07-02 10:57:59.5177 2008-07-02 10:58:06.1738 2008-07-02 10:58:29.4539 2008-07-02 11:00:47.59310 2008-07-02 11:00:50.15711 2008-07-02 11:01:51.15712 2008-07-02 12:45:48.97040 2008-06-24 00:00:00.00041 2008-07-01 00:00:00.00042 2008-07-02 00:00:00.000now 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. |
 |
|
|
|
|
|
|
|