I have tables in a MySQL database like this...
CREATE TABLE `someUserTable`
(
userId INT NOT NULL,
.....
PRIMARY KEY(userId),
);
CREATE TABLE `someActivityTable`
(
activityId INT NOT NULL
userId INT,
.....
PRIMARY KEY(activityId),
KEY(userId)
);
And if I want to find all the activity for a user (let say '100'), is it more efficient to
SELECT *
FROM someUserTable U
LEFT JOIN someActivityTable A ON A.userId = U.userId
WHERE U.userId = 100;
or
SELECT *
FROM someUserTable U
LEFT JOIN
(SELECT * FROM someActivityTable WHERE userId = 100) A ON A.userId = U.userId
WHERE U.userId = 100;
-----Edit-----
Using a profiler will tell me what is best for the current situation. But what I am interested in is the theory behind the 2 queries.
So that in future, I can know which query is better when doing development.
Otherwise, I need to want until the application goes into production and the database starts filling up before I can do an accurate profiling. And by that time, it might be too late.