'I'm trying to create a SQL query using an inner join but I'm getting a syntax error for my first inner join statement

SELECT 
    u.userId, u.firstName, u.lastName, u.emailAddress, 
    u.phoneNumber, ap.date, ap.time, a.balance 
FROM 
    users u 
WHERE 
    u.firstName = 'first_name' 
    AND u.lastName = 'last_name' 
    AND u.emailAddress = '[email protected]' 
INNER JOIN 
    accounts a ON u.userId =  a.userId 
INNER JOIN 
    appointments ap ON u.userId = ap.userId;
sql


Solution 1:[1]

Your query syntax sequence is wrong. If you want to JOIN any table it should come after your parent table.

SELECT u.userId, u.firstName, u.lastName, u.emailAddress, u.phoneNumber, ap.date, ap.time, a.balance 
FROM users u 
INNER JOIN accounts a ON u.userId = a.userId 
INNER JOIN appointments ap ON u.userId = ap.userId
WHERE u.firstName = 'first_name' AND u.lastName = 'last_name' AND u.emailAddress = '[email protected]';

Check on https://www.w3schools.com/mysql/mysql_join.asp

Solution 2:[2]

Your JOIN statements go before the WHERE clause:

SELECT
    u.userId,
    u.firstName,
    u.lastName,
    u.emailAddress,
    u.phoneNumber,
    ap.date,
    ap.time,
    a.balance 
FROM
    users u  
    INNER JOIN accounts a ON u.userId =  a.userId 
    INNER JOIN appointments ap ON u.userId = ap.userId
WHERE
    u.firstName = 'first_name'
    AND u.lastName = 'last_name'
    AND u.emailAddress = '[email protected]';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 paresh
Solution 2 HardCode