Jump to content

Recommended Posts

Hi,

Is there a way to simplify this query?

 

SELECT * FROM mlbplayers p, mlbhstats hs, mlbteams t, mlbpositions pos, mlbplayer_positions ppos

WHERE ppos.position_id=6

AND p.player_id=hs. player _id

AND ppos. player =p. player _id

AND hs.mlbteam_id=t.mlbteam_id

AND hs.year = 2007

GROUP BY p.player_id

ORDER by hs.hr DESC

LIMIT 0,10;

 

Link to comment
https://forums.phpfreaks.com/topic/152696-simplify-query/
Share on other sites

There's a pretty good join tutorial here:  http://www.phpfreaks.com/tutorial/data-joins-unions

 

You want something similar to:

 

select p.*, hs.*, t.*, pos.*, ppos.*

from p

join p using player_id

join ppos using player_id

join hs using mlbteam_id

where ppos.position_id = 6

and hs.year = 2007

order by player_id, hr desc

 

Granted, that probably has some errors in it and you'll need to fix the table names, but it should give you a basic idea to start with.  Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/152696-simplify-query/#findComment-802705
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.