I have 2 tables, one is called items, and the other is called sliders.
I want to call all the columns where sliders.item_id = items.id , and both are published so items.published=1 and sliders.published=1. But also I want to call sliders.item_id's that are NULL.
So basicly is like a right join where i get all related record that match the constrain but also records on the sliders table that don't correspond to items table.
In few words the point is this: i want to get ALL sliders that belongs to items (sliders.item_id=items.id) AND (sliders.published=1 AND items.published=1) BUT also sliders where item_id=null.
I have made a working query, but it does not satisfy me.
select *
from items
right join sliders
on items.id = 27
and items.id = sliders.item_id
and items.published = 1
where sliders.published = 1
THE TABLES
CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`item_description` text NOT NULL,
`published` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `sliders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pic_path` text NOT NULL,
`item_id` int(11) DEFAULT NULL,
`published` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
First i want it in basic MySQL query because i can convert in cakephp later.