MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 10th, 2005, 11:58 AM
il_duce il_duce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 5 il_duce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 31 sec
Reputation Power: 0
Question How to order an unknown field?

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?

Reply With Quote
  #2  
Old February 10th, 2005, 12:38 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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.
Comments on this post
il_duce disagrees: Excellent

Reply With Quote
  #3  
Old February 10th, 2005, 03:03 PM
il_duce il_duce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 5 il_duce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 31 sec
Reputation Power: 0
Thanks!!!!

I'll give it a try.

Reply With Quote
  #4  
Old February 14th, 2005, 10:08 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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 =)

Reply With Quote
  #5  
Old February 14th, 2005, 10:22 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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.

Reply With Quote
  #6  
Old February 14th, 2005, 10:32 AM
il_duce il_duce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 5 il_duce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 31 sec
Reputation Power: 0
it also works on version 3.23.56

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > How to order an unknown field?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT