Solved

MySQL Query

Posted on 2013-01-28
1
150 Views
Last Modified: 2013-01-28
This query correctly returns 94 rows of data...

SELECT pj.pname 'Project Name'
FROM project pj
WHERE pj.deleted = 'N'
AND pj.pstatus = 'Active'
ORDER BY pj.project_num;

I added a column to the query from the budget table and now I get a Carterian Pordect or 521 rows, even with a valid join condition.

SELECT pj.pname 'Project Name', bu.capital_id 'CAP'
FROM project pj
LEFT JOIN budget bu ON (bu.project_id = pj.project_id)
WHERE pj.deleted = 'N'
AND pj.pstatus = 'Active'
ORDER BY pj.project_num;
0
Comment
Question by:hdcowboyaz
1 Comment
 
LVL 10

Accepted Solution

by:
deviprasadg earned 500 total points
ID: 38829885
Looks like there are multiple records in budget table for each project_id.

In such a case if you need a maximum or minimum or Avg etc..
You need to add a group by on pj.pname

Refer: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question