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
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.
ujl · Jun 30, 2019 3:06 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?
phone · Jun 30, 2019 3:56 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
ujl · Jun 30, 2019 4:17 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. .
phone · Jun 30, 2019 4:30 PM
SELECT * FROM Member WHERE EmployementStatus = 'Employee'; This query will fetch all the rows where member are employed.
ujl · Jun 30, 2019 4:46 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');
anarchy99 · Jun 30, 2019 10:50 PM
Thank you anarchy99.
phone · Jul 1, 2019 1:22 PM
Hello ananchy99, Can you share some tips to learn complicated SQL skripts/queries? Thank you.
phone · Jul 1, 2019 3:18 PM
This --https://www.w3schools.com/sql/...
maxpayne · Jul 1, 2019 3:30 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 ?
nepalichoro123 · Jul 1, 2019 3:52 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion