I'm creating a restaurant review website. In my comments table I have a foreign key called user_id and idk how can I use it to display the username from the users table
My user table My comment form
So my question is how to display the username? What mysql statements do I have to write. I don't know what to do
P粉1908832252023-09-10 11:53:52
Suppose you want to try to get the comment text and username from the corresponding user, you can use a join to combine the information, for example:
SELECT u.username, r.review_text FROM reviews r LEFT JOIN users u ON (u.user_id = r.user_id)
I assume the users table is called users
and the reviews table is called reviews
, but update those tables as needed, each "aliased" to u and r respectively, and then the table Yes has joined