အားလုံးပဲ မင်္ဂလာပါ။ ကျွန်တော် Leetcode က Database နဲ့ ပါတ်သက်တဲ့ problem တွေကို ရက်ပေါင်း 30 တစ်ရက်ကို တစ်ခုနှုန်းနဲ့ challenge လေးလုပ်ဖို့ စီစဉ်ဖြစ်ခဲ့ပါတယ်။ ပထမဦးဆုံး အနေနဲ့ problem 577. Employee Bonus ဆိုတဲ့ problem လေးကို solve လုပ်သွားမှာပဲဖြစ်ပါတယ်။ ဒီ problem မှာ ကျွန်တော်တို့ကို Employee နဲ့ Bonus ဆိုတဲ့ table 2 ခုကိုပေးထားပြီး empId ကို Bonus table ထဲမှာ Foreign Key အနေနဲ့ ချိတ်ထားပါတယ်။ Bonus 1000အောက် လျော့တဲ့ Employee နဲ့ Bonus လုံးဝမရတဲ့ Employee တွေကို ရှာပေးရမှာပဲဖြစ်ပါတယ်။
![]()
ပေးထားတဲ့ Example မှာဆိုရင် Bonus table ထဲမှာ id 2 နဲ့ 4 ပဲရှိပါတယ်။ အဲ့နှစ်ခုထဲမှာမှ 2 တစ်ခုထဲ Bonus 1000အောက် လျော့နေတာဖြစ်ပါတယ်။ အဲ့တော့ empId 4 ကလွှဲရင် ကျန်တဲ့ employee တွေအကုန် output မှာပါရမှာပဲဖြစ်ပါတယ်။ အိုကေ ဒါဆို ကျွန်တော်တို့ အဖြေလေးရေးလိုက်ကြရအောင်ဗျာ။
1SELECT e.name, b.bonus from Employee e LEFT JOIN Bonus b on e.empId = b.empId where b.bonus < 1000 OR b.bonus is Null;ဒီ SQL လေးမှာဆို ပထဆုံးကျွန်တော်တို့ က employee name နဲ့ bonus ဆိုတဲ့ column နှစ်ခုကို output အနေနဲ့ select လုပ်လိုက်ပါတယ်။ အဲ့ မှာမှ Employee နဲ့ Bonus table ကို Left join (Left outer join) join လိုက်ပါတယ်။ ဒီနေရာမှာ ဘာလို့ Left Join join ရတာလဲ။
Left Join(Left Outer Join)
Left Join ဆိုတာ က table 2 ခုရှိတယ် Left table ဘက်မှာရှိတဲ့ data တွေအကုန်လိုချင်တယ် right ဘက်မှာ မပါရင် null value အနေနဲ့ ဝင်မယ်ဆိုတဲ့ ပုံစံဖြစ်တယ်။
Example ပေးထားတဲ့ Employee နဲ့ Bonus table ကို ကြည့်ရင် Bonus table ထဲမှာ empId 2 နဲ့ 4 ပဲပါတယ်။ ဒီ table 2 ခုကို Employee table ကို left နေရာထားပြီး join လိုက်ရင် Bonus table ထဲမှာ မရှိလည်း null column အနေနဲ့ ဝင်သွားမှာပဲဖြစ်ပါတယ်။ လိုချင်တဲ့ condition အရ left Join join လိုက်တာပဲဖြစ်ပါတယ်။ နောက်က condition မှာဆို သူလိုချင်တဲ့အတိုင်း Bonus က 1000ဆအာက်ငယ်တာ ဒါမှမဟုတ် လုံးဝမရတာ null value တွေကို ဆွဲထုတ်လိုက်တော့ လိုချင်တဲ့ output ရရှိသွားမှာပဲဖြစ်ပါတယ်။ Video အနေနဲ့ ကြည့်ချင်ရင်တော့ အောက်က YouTube link လေးမှာသွားရောက်ကြည့်ရှု့လို့ရပါတယ်။ နောက်ရက်တွေမှာပြန်တွေ့ကြမယ်ဗျာ see you.
Day-1
Watch on YouTubeDiscussion
Join the conversation
How do you feel about this article?
Comments
Sign in to join the conversation
Sign in to be the first to comment!
Share Your Article
Share with your professional network
Recent Articles

Day 2 - GitHub Actions ရဲ့ အဓိက Concepts များနှင့် Runner အကြောင်း
ပြီးခဲ့တဲ့အပတ် Day 1 တုန်းက ကျွန်တော်တို့ CI/CD ရဲ့ Concept တွေကို အကြမ်းဖျင်း ပြောခဲ့ကြပြီးပြီနော်။ ဒီနေရာမှာ လက်တွေ့မစ...
Day 1 - Software Development ကို ပိုပြီးမြန်စေမယ့် CI/CD
Software တစ်ခုရေးပြီးပြီဆိုရင် "ငါ့စက်ထဲမှာတော့ အလုပ်လုပ်တယ်" ဆိုရုံနဲ့ မပြီးသေးပါဘူး။ User တွေသုံးမယ့် Server ပေါ်ရောက်...

Secure AWS ECR Github Action Using OIDC
Modern DevOps နှင့် Cloud Security တို့မှာ အဓိကဖြစ်လာသည့် Authentication System ယနေ့ခေတ် DevOps, Cloud Engineering, CI/C...

Manual vs Automated Infrastructure: Why "useradd" Still Matters in the Terraform Era
DevOps careerကို လျှောက်နေတဲ့သူတိုင်း Terraform၊ Ansible စတဲ့ Infrastructure as Code (IaC) tools တွေရဲ့ အလုပ်လုပ်နိုင်စွ...
From Surviving to Thriving
“AI ကြောင့် developer အလုပ်ပျောက်သွားမလား?” ဆိုတဲ့ မေးခွန်းကို Junior developer တိုင်း စဉ်းစားဖူးကြမှာပါ။ ဈေးကွက်အခြေအနေ...

