I'm selecting data to output posts a user has book marked.
The main table which holds the id
s of the posts
a user has bookMarked, is called bookMarks
. This is the table based on which posts
will be selected from the posts
table, to display to the user.
bookMarks
id | postId | userId
--------------------------
1 | US01 | 1
2 | US02 | 1
3 | US01 | 2
4 | US02 | 2
posts
id | postId | postTitle
--------------------------
1 | US01 | Title 1
2 | US02 | Title 2
3 | US03 | Title 3
4 | US04 | Title 4
My sql is currently like this:
select a.postsTitle
from posts a
inner join bookmarks b
on b.userId = a.userId
and b.userId = :userId
Notice, I have the table posts
put first before the table bookmarks
. But, since I'm selecting based on whats there in bookmarks
, is it necessary I declare the table bookmarks
first instead of post
in the sql statement? Will doing it the way I'm doing it cause and problems in data selection or efficiency?
Or should I do it like:
select b.postsTitle
from bookmarks a
inner join posts b
on a.userId = b.userId
and a.userId = :userId
Notice, I have table bookmarks
put first here.