I am trying to get information from a big query using 2 main tables (projects and test_cases), the problem is that this query only returns the information when the primary key matches on both tables. Meaning that if I have registers on "projects" but none matches on test_cases all the "left" table information is not displayed.
I am expecting normal values on a typical "left join" clause (If values does not match, every other field is filled with "null" information.
This is the structure from both tables: Projects: ID, Project_Name, N_TestCases, Start_Date, PTF, Status. Test_Cases: ID, IDProject, TC_Description, Remarks, Status, Latest_Update.
I had two projects registered on the table "Projects" and just one on "Test_Cases".
This is the query I made:
SELECT projects.ID, projects.Project_Name, projects.N_TestCases, (SUM(case when test_cases.Status = 'PASS' then 1 else 0 end)+SUM(case when test_cases.Status = 'PASS' then 1 else 0 end)) as 'Complete', SUM(case when test_cases.Status = 'PASS' then 1 else 0 end) as 'PASS', SUM(case when test_cases.Status = 'FAIL' then 1 else 0 end) as 'FAIL', SUM(case when test_cases.Status = 'Blocked' then 1 else 0 end) as 'Blocked', SUM(case when test_cases.Status = 'WNE' then 1 else 0 end) as 'WNE', SUM(case when test_cases.Status = 'Running' then 1 else 0 end) as 'Running', (projects.N_TestCases-SUM(case when test_cases.Status = 'PASS' then 1 else 0 end)-SUM(case when test_cases.Status = 'FAIL' then 1 else 0 end)-SUM(case when test_cases.Status = 'Running' then 1 else 0 end)) as 'Pending', projects.Start_Date,projects.PTF,projects.Status FROM projects INNER JOIN test_cases ON projects.ID = test_cases.IDProject;
This query works as long as I have a second register on "Test_Cases" using the main relation ID (Projects.ID/Test_Cases.IDProject). Otherwise, I only get the information for a single project. (Refer to attached image)Single Project
I had also tried LEFT-JOIN, RIGHT-JOIN, INNER-JOIN, CROSS-JOIN but none of this worked. One of the things I had also discovered is that if I remove very operation and use a single query like "SELECT * from Projects LEFT JOIN Test_Cases ON Projects.ID = Test_Cases.IDProject;", I get the results I want.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.