MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 2nd, 2013, 09:50 AM
bads bads is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 33 bads User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 22 m 35 sec
Reputation Power: 1
Mysql-query-notin

hello! I have this tables in my database, hours containing (8:00,8:30,9:00, 9:30, 10:00, 10:30, 11:00, 11:30)
and schedules table having columns starttime and endtime.
starttime has 8:00 and endtime has 9:00

how can I remove 8:30 and 9:00 from hours
I use this not in. But only removes 8:00
PHP Code:
 select hourtitle from hours where (hourtitlenot in (select starttime from schedules


Any idea??

Reply With Quote
  #2  
Old February 2nd, 2013, 11:13 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 9 sec
Reputation Power: 4140
in order for us to help you with this type of problem (where the sql you posted looks okay but the results are not what you expect) you will need to provide two things:

1. CREATE TABLE statements for the tables
2. sample data in the form of INSERT statements

both of these can be easily provided by dumping the tables
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old February 3rd, 2013, 08:36 AM
bads bads is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 33 bads User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 22 m 35 sec
Reputation Power: 1
Thanks for the reply.

This is the create for schedules
PHP Code:
'schedules''CREATE TABLE `schedules` (
  `schedid` int(3) NOT NULL AUTO_INCREMENT,
  `recordid` int(3) NOT NULL,
  `patname` varchar(45) NOT NULL,
  `schedtype` varchar(45) NOT NULL,
  `scheddate` date NOT NULL,
  `room` varchar(45) NOT NULL,
  `starttime` time NOT NULL,
  `endtime` time NOT NULL,
  `status` varchar(45) NOT NULL,
  `therapist` varchar(45) NOT NULL,
  PRIMARY KEY (`schedid`),
  KEY `recordid` (`recordid`)
) ENGINE=InnoDB AUTO_INCREMENT=95 DEFAULT CHARSET=latin1' 


This is the create for hours
PHP Code:
'hours''CREATE TABLE `hours` (
  `hourid` int(3) NOT NULL AUTO_INCREMENT,
  `hourtitle` time NOT NULL,
  `status` varchar(45) NOT NULL,
  PRIMARY KEY (`hourid`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1' 


This is the insert for schedules
PHP Code:
 INSERT INTO `schedules`(`schedid`, `recordid`, `patname`, `schedtype`, `scheddate`, `room`, `starttime`, `endtime`, `status`, `therapist`) VALUES ('1','1''Sample Patientname','Intake Interview','2013-01-03','Room 1','10:00:00','11;00:00','Ongoing','Therapist Name'


This is the insert for hours
PHP Code:
 INSERT INTO `hours`(`hourid`, `hourtitle`, `status`) VALUES ('1','10:00:00''Available'



=(

Reply With Quote
  #4  
Old February 3rd, 2013, 08:57 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 9 sec
Reputation Power: 4140
thanks

i tried your query on your data and it works great


Reply With Quote
  #5  
Old February 3rd, 2013, 03:42 PM
bads bads is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 33 bads User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 22 m 35 sec
Reputation Power: 1
Thanks! so what is the problem sir? =)

Reply With Quote
  #6  
Old February 3rd, 2013, 05:26 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 9 sec
Reputation Power: 4140
Quote:
Originally Posted by bads
Thanks! so what is the problem sir? =)
hey, it's your data, and your requirement, so if there's a problem, you gotta tell me

Reply With Quote
  #7  
Old February 4th, 2013, 09:29 PM
bads bads is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 33 bads User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 22 m 35 sec
Reputation Power: 1
Quote:
Originally Posted by r937
hey, it's your data, and your requirement, so if there's a problem, you gotta tell me



What about my data sir? I dont encounter something wrong with my data? Maybe its the query?

Reply With Quote
  #8  
Old February 5th, 2013, 02:17 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 32 m 9 sec
Reputation Power: 4140
Quote:
Originally Posted by bads
What about my data sir? I dont encounter something wrong with my data?
the data you gave me had only one row in each table, so obviously, i couldn't find the problem that's in your actual data

in your actual data, there's something wrong which i can't see

if you want me to keep looking into this, you'll have to try to re-create the scenario that you're having

Reply With Quote
  #9  
Old February 10th, 2013, 03:25 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 43 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by bads
hello! I have this tables in my database, hours containing (8:00,8:30,9:00, 9:30, 10:00, 10:30, 11:00, 11:30)
and schedules table having columns starttime and endtime.
starttime has 8:00 and endtime has 9:00

how can I remove 8:30 and 9:00 from hours
I use this not in. But only removes 8:00
select hourtitle from hours where (hourtitle) not in (select starttime from schedules)

Any idea??


Hi,

I'm a bit unclear on the question. if you are nesting the query "select starttime from schedules" and the startime only contains 8:00 , then of course it will only remove 8:00 !
you could remove 9:00 using "not in (select endtime from schedules)" but how would you expect this query to remove 8:30 ? where would it find that value in order to know it needs to be removed?

as a guess, what you are looking for is something more like this:
Quote:
select hourtitle from hours where (hourtitle) not between (select starttime from schedules) and (select endtime from schedules)

Reply With Quote
  #10  
Old February 11th, 2013, 07:34 AM
bads bads is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 33 bads User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 22 m 35 sec
Reputation Power: 1
Quote:
Originally Posted by bobert123
Hi,

I'm a bit unclear on the question. if you are nesting the query "select starttime from schedules" and the startime only contains 8:00 , then of course it will only remove 8:00 !
you could remove 9:00 using "not in (select endtime from schedules)" but how would you expect this query to remove 8:30 ? where would it find that value in order to know it needs to be removed?

as a guess, what you are looking for is something more like this:


Hello thanks for the reply! FYI it is a scheduling program. First, the time schedules are based on HOURS table which has 8:00, 8:30, 9:00, 9:30 and so on. 30 mins interval.

Now, if the the time slot 8:00-9:00 is taken, I want to remove 8:00, 8:30, 9:00 from the choices which is HOURS table because obviously it is taken. The second table is SCHEDULES table that has columns of STARTTIME and ENDTIME. Btw, the query that you've given me says "Subquery returns more than 1 row". I hope I explained it well. =)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Mysql-query-notin

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap