Hi Bob, the link between the tables is on CPUTeam (is in Game_Match) = CountryID (is in Country)
Main Topics
Browse All TopicsI'm trying to get a query result about whether a particular user has won against each country (listed by the query below).
How can I do this?
Here's a list of all the cricketing countries:
SELECT *
FROM `Country`
WHERE `CricketingCountry` =1
AND `ActualCountry` =1
and the table where the results are stored
SELECT CPUTeam
FROM Game_Match
WHERE UserID =1
AND Result = 'won'
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
if countryid field is in both tables, then this should work, but I'm not sure we are talking about the same thing. Can you post the table schema for both tables?
SELECT CPUTeam, countryId
FROM Game_Match
WHERE UserID =1
AND Result = 'won'
JOIN Game_Match.countryId=Count
WHERE CricketingCountry =1
AND ActualCountry =1
Sorry Bob, this is the join statement:
JOIN Game_Match.CPUMatch = Country.CountryID
What that won't give me though is a result of whether the user has won against every country returned by the following query:
SELECT *
FROM `Country`
WHERE `CricketingCountry` =1
AND `ActualCountry` =1
I'd like to get a result of something like 0 if the user hasn't won against all the countries, or 1 if the user has won against all the countries.
Got the query going myself in this in that it lists a count of the number of countries remaining to be beaten. If someone knows a better more efficient way of doing this, I'm all ears. Cheers.
SELECT count( * )
FROM Country
WHERE `CricketingCountry` =1
AND `ActualCountry` =1
AND CountryID NOT
IN (
SELECT CPUTeam
FROM Game_Match
WHERE UserID =1
AND MatchTypeId
IN ( 1, 3, 4 )
)
Business Accounts
Answer for Membership
by: BobLambersonPosted on 2008-12-13 at 21:48:46ID: 23166722
what other fields do you have available in the game_match table? you need some kind of relationship or common field in bothCountry table and Game_Match table.
Then you can join the two tables on that common field, something like:
SELECT CPUTeam
FROM Game_Match
WHERE UserID =1
AND Result = 'won'
JOIN Game_Match.<commonField>=Cou ntry.<commo nField>
SELE CT *
FROM `Country`
WHERE `CricketingCountry` =1
AND `ActualCountry` =1