Jump to content

Recommended Posts

I want to display the SUM of shot for all HOLE played in 2009 (my date field are 2009-05-05 so I can use LIKE "%2009%")

But the date field is only in the GAME table.

 

TABLE game

FIELD idGame, date, idPlayer

 

TABLE hole

FIELD idGame, idPlayer, shot

 

I tried to do : (at least to display all the holes even if its not 2009)

SELECT * FROM game WHERE idJoueur = 2 INNER JOIN hole ON hole.idGame = game.idGame

 

I get the error message :

Error of syntax 'INNER JOIN hole ON hole.idGame = game.idGame

 

Where am I wrong ?

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/158519-sql-query-need-help/
Share on other sites

First of all, what is idJoueur? Is that the idPlayer? But of which table? And like Mchl said, don't store dates as strings.

 

You have to put the INNER JOIN before the WHERE clause.

 

I would do something like this provided that idJoueur is the idPlayer and your date is correctly changed to datatype of DATE.

SELECT SUM(g.shot) AS sum_shots
FROM game g
INNER JOIN hole h
     ON (h.idGame = g.idGame)
WHERE DATE_SUB(CURDATE(), INTERVAL 0 YEAR) <= g.date
     AND g.idPlayer = 2

Link to comment
https://forums.phpfreaks.com/topic/158519-sql-query-need-help/#findComment-836035
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.