Re: Help with a query

From: Date: Wed, 23 Apr 2003 03:23:54 +0000
Subject: Re: Help with a query
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-27288@lists.php.net to get a copy of this message
shaun, not sure, but try this: SELECT B.* FROM WMS_User U, WMS_Bookings B WHERE B.User_ID = '1' AND B.Booking_Start_Date >= '2003-04-28' AND B.Booking_End_Date <= '2003-04-29' AND B.User_ID = U.User_ID I think you need to have that last part in there. I'm assuming the user id field in the WMS_User table is 'User_ID' -Jake "Shaun" <shaun@mania.plus.com> wrote in message news:20030422220907.8972.qmail@pb1.pair.com... > Hi, > > I have a table in my MySQL database called bookings: > > CREATE TABLE WMS_Bookings ( > Booking_ID int(11) DEFAULT '' NOT NULL auto_increment, > User_ID int(11) DEFAULT '0' NOT NULL , > Project_ID int(11) DEFAULT '0' NOT NULL , > Rep_ID int(11) DEFAULT '0' NOT NULL , > PCT_ID int(11) DEFAULT '0' NOT NULL , > Practice_ID int(11) DEFAULT '0' NOT NULL , > Booking_Start_Date date DEFAULT '0000-00-00' NOT NULL , > Booking_End_Date date DEFAULT '0000-00-00' NOT NULL , > Booking_Days int(11) DEFAULT '1' NOT NULL , > Booking_Hours decimal(3,2) DEFAULT '0.00' NOT NULL , > Booking_Mileage int(5) , > Booking_Status int(2) DEFAULT '0' NOT NULL , > Work_Type varchar(20) DEFAULT '' NOT NULL , > Additional_Notes text , > PRIMARY KEY (Booking_ID,User_ID,Project_ID,Rep_ID,PCT_ID) > ); > > How can i check whether a user is already booked for a given period? I > have tried the following query but this only checks for a booking that > starts before the gaiven date and ends after it > > SELECT B.* > FROM WMS_User U, WMS_Bookings B > WHERE B.User_ID = '1' > AND B.Booking_Start_Date >= '2003-04-28' > AND B.Booking_End_Date <= '2003-04-29' > > if a user is booked from 2003-04-29 to 2003-05-01 then the query returns no > rows... > > Thanks for your help > > > >

« previous php.db (#27288) next »