Skip to content
Advertisement

MYSQL JOINS, Got Stuck [closed]

good day! i’m in the middle of learning new thing in mysql, i need join 2 tables, table aktifitas_materi and table hari, i tried many join, but i think this is the closest one…

i’m using sql like this SELECT * FROM hari LEFT JOIN aktifitas_materi ON hari.id_hari = aktifitas_materi.id_hari WHERE id_materi = '1631246767791' AND id_user = '1631016713249' UNION ALL SELECT * FROM hari LEFT JOIN aktifitas_materi ON hari.id_hari = aktifitas_materi.id_hari

this is looks good, but when i change id_materi or id_user, the data still the same, Even though the data should be null, idk why this happen, please helppp, where’s the problem? 🙁

THE PROBLEM: I think my data didn’t get filter by where, because when i change id_materi or id_user, i got all the data…

EXPECTED RESULT

When i change id_materi or id_user to another number, i got data looks like this expected table


Schema (MySQL v5.7)


Query #1

id_hari hari timestamp id_aktifitas_materi id_materi id_user
1 Intro 2021-09-10 11:01:13 1631271674591 1631246767791 1631016713249
1 Intro 2021-09-10 11:01:13 123213213 23234234 123213213
Hari 1
Hari 2
Hari 3
Hari 4
Hari 5
Hari 6
Hari 7

View on DB Fiddle

Advertisement

Answer

I GOT MY ANSWER!!!

changed my sql to select * from hari left join (select * from aktifitas_materi where id_materi = '' and id_user = '') tm on hari.id_hari = tm.id_hari

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement