← Back to Kurakani

Need help on Sql query

Original Post

​Hello , I have a table called Member consisting of Columns MemberName, MotherName, and EmploymentStatus. I would like to create a query which gives me MemberName, MotherName, and EmploymentStatus in which the Mother's all Daughers are Emplpyee . In my table below I want row 1 as a result of the query.

phone
Jun 30, 2019 2:36 PM · 15,986 views
10 Replies
ujl Jun 30, 2019 3:06 PM
You need to create another table with mother daughter relationship. In real life, your table above will have actual names! It will be pretty confusing who is whose daughter without a separate table. Then, you can use foreign key to link that table with this table.
phone Jun 30, 2019 3:56 PM
Hi Ujl, Thank you for your reply. I already have a table in this format and it is not feasible to make another table quickly. Can someone suggest the query for the same table, please?
ujl Jun 30, 2019 4:17 PM
SELECT * FROM Member WHERE MotherName = 'GrandMother1' AND EmployementStatus = 'Employee'; The above query will bring row 1 as a result. Last edited: 30-Jun-19 04:18 PM
phone Jun 30, 2019 4:30 PM
Hi ujl, Thanks for your reply. In my table thousands of records where only some members of the same mother are employed. The query should be able to fetch the records of all mothers whose daughters are employed. .
ujl Jun 30, 2019 4:46 PM
SELECT * FROM Member WHERE EmployementStatus = 'Employee'; This query will fetch all the rows where member are employed.
anarchy99 Jun 30, 2019 10:50 PM
not optimized... SELECT * FROM phonesTable pt1 WHERE pt1.EmployeeStatus = 'Employee' AND pt1.MemberName IN (select pt2.MotherName from phonesTable pt2 where pt2.EmployeeStatus = 'Employee') AND pt1.MemberName NOT IN (select pt3.MotherName from phonesTable pt3 where pt3.EmployeeStatus = 'Unemployee');
phone Jul 1, 2019 1:22 PM
Thank you anarchy99.
phone Jul 1, 2019 3:18 PM
Hello ananchy99, Can you share some tips to learn complicated SQL skripts/queries? Thank you.
maxpayne Jul 1, 2019 3:30 PM
nepalichoro123 Jul 1, 2019 3:52 PM
i am electrical engineer by profession. i think above type of queries i can do myself . will that make me capable of applying for entry level sql developer ?
Login to join the conversation.

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all
Ask Sajha AI Assistant