The following script allows you to create the database and populate it with necessary data for my question:
# HeidiSQL Dump
#
# --------------------------------------------------------
# Host: 127.0.0.1
# Database: blueskylearning
# Server version: 5.1.22-rc-community
# Server OS: Win32
# Target-Compatibility: MySQL 5.0
# Extended INSERTs: Y
# max_allowed_packet: 1048576
# HeidiSQL version: 3.0 Revision: 572
# --------------------------------------------------------
/*!40100 SET CHARACTER SET latin1*/;
#
# Database structure for database 'windowsLinuxProblem'
#
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `windowsLinuxProblem` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `windowsLinuxProblem`;
#
# Table structure for table 'organization'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ `organization` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
#
# Dumping data for table 'organization'
#
/*!40000 ALTER TABLE `organization` DISABLE KEYS*/;
LOCK TABLES `organization` WRITE;
REPLACE INTO `organization` (`id`, `name`) VALUES
(1,'Org1');
UNLOCK TABLES;
/*!40000 ALTER TABLE `organization` ENABLE KEYS*/;
#
# Table structure for table 'resource'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ `resource` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`resourcePublic` tinyint(4) NOT NULL,
`active` tinyint(4) NOT NULL,
`published` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=534 DEFAULT CHARSET=utf8;
#
# Dumping data for table 'resource'
#
/*!40000 ALTER TABLE `resource` DISABLE KEYS*/;
LOCK TABLES `resource` WRITE;
REPLACE INTO `resource` (`id`, `title`, `resourcePublic`, `active`, `published`) VALUES
(1,'Title number 1',1,1,1),
(2,'Title number 2',1,1,1),
(3,'Title number 3',1,1,1),
(4,'Title number 4',1,1,1),
(5,'Title number 5',1,1,1),
(6,'Title number 6',1,1,1);
UNLOCK TABLES;
/*!40000 ALTER TABLE `resource` ENABLE KEYS*/;
#
# Table structure for table 'resourceorganization'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ `resourceorganization` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`resource_id` int(11) NOT NULL,
`organization_id` int(11) NOT NULL,
`forever` tinyint(4) NOT NULL,
`startDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`endDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `resource_id` (`resource_id`),
KEY `organization_id` (`organization_id`),
CONSTRAINT `resourceorganization_ibfk_1` FOREIGN KEY (`resource_id`) REFERENCES `resource` (`id`),
CONSTRAINT `resourceorganization_ibfk_2` FOREIGN KEY (`organization_id`) REFERENCES `organization` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8;
Could someone help me understand why the following query does not fetch all the resources with active=1, published=1, resourcePublic=1
Query:
select *
from
resource resource0_,
resourceOrganization resourceor1_
where
resource0_.active=1
and resource0_.published=1
and (
resource0_.resourcePublic=1
or resourceor1_.resource_id=resource0_.id
and resourceor1_.organization_id=2
and (
resourceor1_.resource_id=resource0_.id
and resourceor1_.forever=1
or resourceor1_.resource_id=resource0_.id
and (
current_date between resourceor1_.startDate and resourceor1_.endDate
)
)
)