希望這可以幫助:
SELECT
p.post_id, p.user_id, p.post_title, p.post_content,
u.user_fullname
// column name from two or more tables
// eg: table_name.column_name
// use p and u, because we already give temporary name for table post and user
FROM
post p // table 1: post refer as p (SQL aliases)
JOIN // combine 2 column from two or more tables
user u // table 2: user refer as u (SQL aliases)
ON
p.user_id = u.user_id // key for joining the table, the ID should be the same
或者您可以使用下面的代碼,而別名:
SELECT
post.post_id, post.user_id, post.post_title, post.post_content,
user.user_fullname
FROM
post
JOIN
user
ON
post.user_id = user.user_id
參見:SQL JOIN
採取胡安的'用戶ID'然後在查詢帖子時使用它 – Swellar
我已編輯帖子,謝謝Carl Jan. –
然後使用搜索值在'User'表中查找一行。如果你有一排,拿它的'用戶ID'。 – Swellar