can any one solve that sql problem please? ex: i have library system project
table 1 for all items
id title item_tybe volume_id
1 php book null
2 asp magazine 1
2 perl magazine 2
table 2 for volume which have related with table 1 but with magazine only
id volume approved
1 vol1 yes
1 vol2 no
i want get all items (book - magazine ) but i want get magazine which her volume approved = yes
should i should if condition ?? i dont know how please help
Assuming you meant you ONLY want to get magazines that are approved, whilst getting all books:
SELECT title, item_type
FROM table1
LEFT JOIN table2 ON table1.volume_id = table2.id AND table2.approved = 'yes'
Let me know if I misunderstood.
SELECT title, item_type FROM table1
LEFT JOIN table2 ON volume_id = table2.id
WHERE approved IS NULL or approved = 'yes'
try:
select *
from table_1 t1
left join table_2 t2 on t1.volume_id=t2.id and t2.approved='yes'