User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 401,974 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,766 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 54351 | Replies: 3
Reply
Join Date: Sep 2004
Location: Cheltenham, UK
Posts: 20
Reputation: TimmyRaa is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
TimmyRaa's Avatar
TimmyRaa TimmyRaa is offline Offline
Newbie Poster

MySQL nested query / joined query conversion help

  #1  
Sep 13th, 2004
A project that I've been working on (and getting help on here) is just about complete, but I've had to develop it locally on MySQL 4.1 for it's support of nested queries - I'm rubbish with joined queries.

However, the project is going to be running on my host, who runs MySQL 3.x, which doesn't support nested queries. Therefore I'm looking for help on converting the query below, to not use any subqueries so it'll work on my host.

SELECT nickname, count( * ) , sum( score ) , max( score ) , min( score ) , avg( score )
FROM players, scoreslist
WHERE players.playerid = scoreslist.playerid AND scoreslist.matchid
IN (

SELECT matchid
FROM matches
WHERE season =2004
)
GROUP BY nickname
ORDER BY avg( score ) DESC

As you can see, it's a bit of a mix, but any help anyone can give would be great.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Posts: 194
Reputation: PoA is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
PoA PoA is offline Offline
Junior Poster

Re: MySQL nested query / joined query conversion help

  #2  
Sep 14th, 2004
Try the following statement.

SELECT nickname, count( * ) , sum( score ) , max( score ) , min( score ) , avg( score )
FROM players p, scoreslist s
WHERE p.playerid = s.playerid AND s.matchid
IN (

SELECT matchid
FROM matches
WHERE season =2004
)
GROUP BY nickname
ORDER BY avg( score ) DESC
Reply With Quote  
Join Date: Sep 2004
Location: Cheltenham, UK
Posts: 20
Reputation: TimmyRaa is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
TimmyRaa's Avatar
TimmyRaa TimmyRaa is offline Offline
Newbie Poster

Re: MySQL nested query / joined query conversion help

  #3  
Sep 14th, 2004
I'm no SQL expert, but that still looks like it's got a nested query in it. In fact, it's exactly the same as mine, except you've substituted players for p, and scoreslist for s.
Reply With Quote  
Join Date: Sep 2004
Location: Cheltenham, UK
Posts: 20
Reputation: TimmyRaa is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
TimmyRaa's Avatar
TimmyRaa TimmyRaa is offline Offline
Newbie Poster

Re: MySQL nested query / joined query conversion help

  #4  
Sep 15th, 2004
Worked it out...

SELECT nickname AS name, count( * ) AS played, sum( score ) AS agg, max( score ) AS highest, min( score ) AS lowest, avg( score ) AS average
FROM stats_players, stats_scoreslist, stats_matches
WHERE stats_players.playerid = stats_scoreslist.playerid AND stats_scoreslist.matchid = stats_matches.matchid AND stats_matches.season = 2004
GROUP BY nickname
ORDER BY average DESC , name ASC
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 7:01 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC