Re: MYSQL error
| From: | php3 at developersdesk dot com | Date: | Wed, 21 Jun 2000 22:12:01 +0000 |
| Subject: | Re: MYSQL error | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-560@lists.php.net to get a copy of this message | ||
Addressed to: "clayton collie" <ccollie@cau.edu>
php-db@lists.php.net
** Reply to note from "clayton collie" <ccollie@cau.edu> Wed, 21 Jun 2000 05:57:12
-0400
>
> can someone tell me whats wrong with this query ? im using MYSQL
> 3.22.22, so i cant do a condition on an inner join (hence the left
> join). MySQL complains about a syntax error.
>
> select u.UserId, u.LastName, u.FirstName, ts.TestName, ts.Score,
> ts.StartDate, ts.StartTime, ts.TimeSpent,
> from users u, test_scores ts
> left join users on (u.UserId = ts.UserId)
A couple of things...
1. There is no , after the last item in the list
2. You are mixing two join syntaxes.
one would go like this:
SELECT u.UserId, u.LastName, u.FirstName, ts.TestName, ts.Score,
ts.StartDate, ts.StartTime, ts.TimeSpent
FROM users u, test_scores ts
WHERE u.UserId = ts.UserId
Only records in both tables will appear in the result set
The other would be this:
SELECT u.UserId, u.LastName, u.FirstName, ts.TestName, ts.Score,
ts.StartDate, ts.StartTime, ts.TimeSpent
FROM test_scores ts
LEFT JOIN users u on (u.UserId = ts.UserId)
Or possibly this:
SELECT u.UserId, u.LastName, u.FirstName, ts.TestName, ts.Score,
ts.StartDate, ts.StartTime, ts.TimeSpent
FROM test_scores ts
LEFT JOIN users u USING ( UserId )
All records in test_scores will appear in the result, with fields from
users null if no matching users entry exists.
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com