Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Join Help Needed

Author  Topic 

RichardSteele
Posting Yak Master

160 Posts

Posted - 2013-02-18 : 20:16:19
I have two mySQL tables created for a contest. Table 1 has the contestant info, table 2 has the votes. A record is inserted into table 2 whenever there a vote by a judge.

I'd like to show all contestants (all records in table 1) along with their votes, even if no votes have been cast yet.

The following only brings up the contestants that have voted only. Note the jtpJuror is from the JurortoPortfolio as I only want to show votes from that one juror.

SELECT ID, First, Last, jtpVote FROM masterPortfolioTest LEFT JOIN jurorToPortfolio ON mastID=jtpMastID WHERE mastYear=2013 and jtpJuror=111

What would the SQL look like to bring up all contestants regardless if they have received votes or not by the specified juror and show their votes if they have received votes.

Thanks in advance.

RichardSteele
Posting Yak Master

160 Posts

Posted - 2013-02-18 : 20:53:47
Ok, got it.
SELECT ID, First, Last, jtpVote FROM masterPortfolioTest LEFT JOIN jurorToPortfolio ON mastID=jtpMastID AND jtpJuror=111 WHERE mastYear=2013
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-18 : 23:49:04
One thing to note is that this is a forum dedicated to MS SQL Server so there are not enough people with expertise on MySQL. The solutions given here are guaranteed to work only on sql server. So if you're using MySQL, you may be better off posting questions in some MySQL forums like www.dbforums.com

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -