Im having problems with constructing a query which filters out posts from table a, that already existing in table b.
Table A:
`bok_id` int(6) NOT NULL AUTO_INCREMENT,
`tid` time NOT NULL,
`datum` date NOT NULL,
`datum_end` date NOT NULL,
`framtid` varchar(5) NOT NULL,
`h_adress` varchar(100) NOT NULL,
`l_adress` varchar(100) NOT NULL,
`kund` varchar(100) NOT NULL,
`typ` varchar(5) NOT NULL,
`bil` varchar(99) NOT NULL,
`sign` varchar(2) NOT NULL,
`tilldelad` varchar(12) NOT NULL,
`skapad` datetime NOT NULL,
`endrad` datetime NOT NULL,
`endrad_av` varchar(2) NOT NULL,
`kommentar` text NOT NULL,
`weektype` varchar(3) NOT NULL,
`Monday` tinyint(1) NOT NULL,
`Tuesday` tinyint(1) NOT NULL,
`Wednesday` tinyint(1) NOT NULL,
`Thursday` tinyint(1) NOT NULL,
`Friday` tinyint(1) NOT NULL,
`Saturday` tinyint(1) NOT NULL,
`Sunday` tinyint(1) NOT NULL,
`avbokad` varchar(2) NOT NULL,
`unika_kommentarer` varchar(2) NOT NULL,
UNIQUE KEY `bok_id` (`bok_id`)
Table B:
`id` int(6) NOT NULL AUTO_INCREMENT,
`bok_id` int(6) NOT NULL,
`tid` time NOT NULL,
`datum` date NOT NULL,
`datum_end` date NOT NULL,
`framtid` varchar(5) NOT NULL,
`h_adress` varchar(100) NOT NULL,
`l_adress` varchar(100) NOT NULL,
`kund` varchar(100) NOT NULL,
`typ` varchar(5) NOT NULL,
`bil` varchar(99) NOT NULL,
`sign` varchar(2) NOT NULL,
`tilldelad` varchar(12) NOT NULL,
`skapad` datetime NOT NULL,
`endrad` datetime NOT NULL,
`endrad_av` varchar(2) NOT NULL,
`kommentar` text NOT NULL,
`weektype` varchar(3) NOT NULL,
`Monday` tinyint(1) NOT NULL,
`Tuesday` tinyint(1) NOT NULL,
`Wednesday` tinyint(1) NOT NULL,
`Thursday` tinyint(1) NOT NULL,
`Friday` tinyint(1) NOT NULL,
`Saturday` tinyint(1) NOT NULL,
`Sunday` tinyint(1) NOT NULL,
`avbokad` varchar(2) NOT NULL,
`unika_kommentarer` varchar(2) NOT NULL,
UNIQUE KEY `id` (`id`)
What i want is a query which hides all rows in Table A which exists in table B IF Table B.tilldelad=Requested Date. (f.e 2013-09-30)
Im not sure this makes any sense?
What i want is to filter out period bookings as they have been executed and therefore exists in table b which indicates it has been.
Since its recurring events the same bok_id can exists SEVERAL times in table B, but only ONCE in table A...
SELECT * FROM bokningar
WHERE bokningar.datum <= '2013-09-30'
AND bokningar.datum_end >= '2013-09-30'
AND bokningar.typ >= '2'
AND bokningar.weektype = '1'
AND bokningar.Monday = '1' ## Monday this is dynamically changed to current date
AND bokningar.avbokad < '1'
AND NOT EXISTS ( SELECT 1 FROM tilldelade WHERE tilldelade.tilldelad = '2013-09-30' )
The above code does the trick regarding filtering out rows not in table B, however, if one row in table B has the current date, all results are filtered out. Only rows with corresponding bok_id's is supposted to get filtered out.
Any thoughts on how to do that? Perhaps a Distinct select?