| 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.somecolorder by t1.datecol desc KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
mel_06
Starting Member
6 Posts |
Posted - 2009-05-25 : 23:06:57
|
| RankTotal Posts: 64Joined 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… |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-25 : 23:09:38
|
use UNION ALL select datecolfrom table1union allselect datecolfrom table2 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
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. |
 |
|
|
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.likeselect col1, col2, col3 = NULLfrom table1union allselect col1, col2 = NULL, col3from table2union allselect col1, col2, col3from table3 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
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... |
 |
|
|
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] |
 |
|
|
mel_06
Starting Member
6 Posts |
Posted - 2009-05-26 : 00:56:20
|
| ok...how about using the DQL (Doctrine Query Language)? |
 |
|
|
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] |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
|