MySQL Inner Join Query Syntax error

后端 未结 1 1289
暗喜
暗喜 2021-01-20 09:53

I\'m kind of a MySQL novice and can\'t figure out what is going wrong here. I have two tables. The left table is called Workouts. The relevant columns are date

相关标签:
1条回答
  • 2021-01-20 10:32

    Your INNER JOIN should come before the WHERE. I also don't think you needed the parens around your BETWEEN clause, but I doubt that it'll cause an error either way:

    SELECT Workouts.date as date, Workout_locations.location_id as loc_id 
    FROM Workouts 
    INNER JOIN Workout_locations ON Workouts.id=Workout_locations.workout_id
    WHERE Workouts.pacegroup_id = '9' 
    AND Workouts.date BETWEEN '2013-08-19' AND '2013-08-25';
    

    Also, though they technically let you get away with it, you should avoid using "date" as a selected column name (it's a reserved word).

    You could do a bit of streamlining as well to make things a bit easier to read:

    SELECT Workouts.date AS wo_date, Workout_locations.location_id AS loc_id
    FROM Workouts w
    INNER JOIN Workout_locations l ON w.id = l.workout_id
    WHERE w.pacegroup_id = '9'
    AND w.date BETWEEN '2013-08-19' AND '2013-08-25';
    
    0 讨论(0)
提交回复
热议问题