Jump to content

SQL query, need help


kickoutbettman

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.