If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Problem using joins. (V.V.Urgent)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-03-04, 08:25
joydip_kanjilal joydip_kanjilal is offline
Registered User
 
Join Date: Feb 2004
Posts: 21
Problem using joins. (V.V.Urgent)

I am using My SQL 4.0. It doesnot support nested sub queries.
Please use joins.


The following is the structure of the table.


CREATE TABLE `timeslot` (
`timeSlotID` int(12) NOT NULL auto_increment,
`tableID` varchar(12) default '',
`startTime` varchar(20) default '00:00:00',
`endTime` varchar(20) default '00:00:00',
`dayOfWeek` varchar(100) default '0',
`duration` int(12) default '0',
`status` varchar(10) default 'N',
`companyID` int(12) default '0',
PRIMARY KEY (`timeSlotID`)
) TYPE=InnoDB;


I require to display the startTime of the min timeSlotID and the endTime of the max timeSlotID where dayofweek=1. I want the slotuion using joins but not by creating any temporary tables. Consider that there are a lot of records for dayofweek = 1.

The output that I require is like the following:---

StartTime MinTimeSlotID EndTime MaxTimeSlotID
8:00 49 21:45 64

Thanx in advance.
Reply With Quote
  #2 (permalink)  
Old 05-03-04, 09:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
(
select 'MIN'      as resulttype
     , startTime  as thetime
     , timeSlotID
  from timeslot
order 
    by timeSlotID   
limit 1    
)
union all
(
select 'MAX'     
     , endTime    
     , timeSlotID
  from timeslot
order 
    by timeSlotID desc  
limit 1    
)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-09-04, 02:56
joydip_kanjilal joydip_kanjilal is offline
Registered User
 
Join Date: Feb 2004
Posts: 21
Join Problem. (Please suggest an alternative)

Thanx a lot for the answer. Please suggest an alternative without having to use the limit clause. This is because LIMIT is allowed in My SQL but not in other databases.

Thankx a lot once again.
Reply With Quote
  #4 (permalink)  
Old 05-09-04, 04:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
well, i am sorry for giving you a mysql solution in the mysql forum for what you clearly indicated was a mysql problem
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On