အားလုံးပဲ မင်္ဂလာပါ။ ကျွန်တော် 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

AWS - Application Load Balancer
Elastic Load Balancing (ELB) ELB ဆိုတာကတော့ request တွေကို တစ်နေရာတည်းမှ လက်ခံကာ Amazon EC2 instances၊ containers, etc.....

Terraform Day 3: Benefits of Terraform State
Terraform ကိုလေ့လာ တဲ့အခါ ကျွန််တော်တို့ရဲ့ Project Folder ထဲမှာ terraform.tfstate ဆိုတဲ့ ဖိုင်လေးကို တွေ့ဖူးကြပါလိမ့်မယ...

Terraform Day 2: Essential IaC Principles You Must Know
မနေ့ကတော့ Terraform အကြောင်း အကြမ်းဖျင်း Concept ကို ပြောပြခဲ့ပြီးပြီဆိုတော့ ဒီနေ့မှာတော့ Terraform ကို Professional ကျက...

TCP/IP Protocol
အားလုံးပဲမင်္ဂလာပါ။ ဒီနေ့ ကျွန်တော်တို့ TCP/IP Protocol အကြောင်း ဆွေးနွေးသွားပါမယ်။ ပထမဆုံးအနေနဲ့ TCP/IP ရဲ့ History လေး...

Terraform Day 1: Introduction to IAC and Terraform
ကျွန်တော်တို့ cloud အကြောင်း စပြောကြပြီဆိုရင် အရင်ဆုံး ခေါင်းထဲရောက်လာတာ Console ထဲဝင်၊ UI ကနေ ခလုတ်လေးတွေ လိုက်နှိပ်ပြီ...

