|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, I have a MySQL question:
First the background. I inherited a badly designed mysql database. 3 particular tables are of importance to me- HANDSETSALE | ACCESSORYSALE | TOPUPSALE Each of these can be added to at certain points of time and each sale records what date it occurred on. The query I need to run should be able to tell me what distinct dates there are where there was at least one sale. Because each table has a sale field I basically need to perform a distinct SELECT three times. I thought of two good ways of doing this: a UNION select, or a distinct select to a temporary table and then add to it for the other two tables. I have been forced to do the latter because the database is so archaic (vesion 3.23.56). This is my problem - now that I have the result in a temporary table, I cant order it because I dont know what field these dates are stored in. The guy who designed the table called the date field different names according to what table it was in e.g. handsetsaledate, accessorysaledate. So is there a way of ordering this temporary table? |
|
#2
|
|||
|
|||
|
Use an alias when selecting your field into your temp table:
Code:
CREATE TEMPORARY TABLE mytemptable SELECT myfirstdatefield AS finaldate FROM table1 Then you can pull and order by finaldate. |
|
#3
|
|||
|
|||
|
Thanks!!!!
I'll give it a try. |
|
#4
|
||||
|
||||
|
Madpawn, that's crazy...
Does that work in mysql? Which version was it first implemented? I'm asking because I'm too lazy to look it up... If you don't have the answers immediately, just say so and I'll look it up myself =) |
|
#5
|
|||
|
|||
|
I ran it in 4.0.17, but it probably works earlier than that. Not entirely sure if it'll work as needed with more than one table involved, though.
|
|
#6
|
|||
|
|||
|
it also works on version 3.23.56
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > How to order an unknown field? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|