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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DESC 8 tables date field?

Author  Topic 

mel_06
Starting Member

6 Posts

Posted - 2009-05-25 : 22:47:55
hi guys...

my question is how will i query from 8 tables which all have a date field that i must output to a descending order?

needed to get through this problem...

thanks...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-25 : 22:55:10
don't quite understand your problem here . . .

something like this ?

select *
from table1 t1 inner join table2 t2 on t1.somecol = t2.somecol
order by t1.datecol desc



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mel_06
Starting Member

6 Posts

Posted - 2009-05-25 : 23:06:57
Rank
Total Posts: 64
Joined 10-15-2008


all tables have a date field that i must display the results through a descending order…

the query should be like the results came from a single table’s date field…

somehow i need to combine all the date field from all the tables then make my query…

this, really i just don’t know how…

thanks…
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-25 : 23:09:38
use UNION ALL


select datecol
from table1
union all
select datecol
from table2



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mel_06
Starting Member

6 Posts

Posted - 2009-05-25 : 23:19:46
i think UNION ALL must have the same number of columns per table.

but how about each tables has different numbers of columns but all of them surely has a date field.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-25 : 23:24:07
yes. for union, you need the same no of column and same data type for the column. You can use NULL for those tables with less column.
like

select col1, col2, col3 = NULL
from table1
union all
select col1, col2 = NULL, col3
from table2
union all
select col1, col2, col3
from table3



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mel_06
Starting Member

6 Posts

Posted - 2009-05-25 : 23:43:31
but what i only need is the a single column (date field) from all this tables then make aa orderBy DESC...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-25 : 23:52:19
then use the query i posted on 05/25/2009 : 23:09:38


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mel_06
Starting Member

6 Posts

Posted - 2009-05-26 : 00:56:20
ok...

how about using the DQL (Doctrine Query Language)?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-26 : 01:03:11
quote:
Originally posted by mel_06

ok...

how about using the DQL (Doctrine Query Language)?




What is that ? You are not using MS SQL Server are you ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mel_06
Starting Member

6 Posts

Posted - 2009-05-26 : 02:05:20
khtan,

used your code but SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-05-26 : 02:08:21
This is a sql server forum not MySQL (hence it's name).
Can't see anywhere that you mentioned MySQL either or you would heve been pointed elsewhere earlier.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -