Solved

MySQL Query

Posted on 2013-01-28
1
147 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now