mysql - Multiple Join on same table with different columns -
i have problems making sql request.
here tables:
create table dates( id int primary key, obj_id int, dispo_date text ); create table option( id int primary key, obj_id int, random_option int ); create table obj( id int primary key, );
and random date user gives me , options.
i'd select on both tables correspond obj having date equal user's date.
let's date = "22/01/2013" , options = 3.
select * obj inner bring together dates on dates.obj_id=obj.id inner bring together alternative on option.obj_id=obj.id dates.dispo_date="22/01/2013" , option.random_option=3;
that gives me obj table with, each one, same dates , options without filtering anything.
can give me pointers i'm doing wrong ?
solution:
since seemed looking restarted sql server , since, works ...
thanks help , sorry time-loss :-(
as far can see, there nil wrong query.
when seek it, returns obj rows there corresponding date , corresponding option.
insert dates values (1, 1, '22/01/2013'), (2, 1, '23/01/2013'), (3, 2, '22/01/2013'), (4, 2, '23/01/2013'), (5, 3, '23/01/2013'), (6, 3, '24/01/2013'); insert `option` values (1, 1, 4), (2, 1, 5), (3, 2, 3), (4, 2, 4), (5, 3, 3), (6, 3, 4); insert obj values (1), (2), (3)
with info should filter out obj 1 because there no alternative 3 it, , filter out obj 3 because there no date 22 it.
result:
id obj_id dispo_date random_option ------------------------------------- 2 2 22/01/2013 3
demo: http://sqlfiddle.com/#!2/a398f/1
mysql sql join
No comments:
Post a Comment