I am currently reading about inner joins and left joins on W3Schools and was wondering how to pull the correct data for a user. From what I have read so far from sql_join_left and sql_join_inner, these joins pull out all data from the tables. The inner joins pull all matching data from both tables while the left join pull all matching data only from the left table. If I have a user register on my application and the user joins a thread and leaves comments, would the only way to retrieve the correct comment history for that user be to send back the users Primary Key as a reference to the users ID after registration, then loop through all the data I get back with a for loop until the users ID matches the ID I set for comment table.
My Users table has columns Primary Key, First Name, Last Name, Password, Email.
My Comments table has the columns, Primary key, Comment, and User ID (this is the primary key the user is assigned after registration and I will be using this column to match with the primary key in the Users table in the for loop. Also since this column is a reference to the users Primary Key in the Users table, it is okay to have multple IDs that are the same which will be referencing the same user?)
Would this be the correct approach to retrieve the correct data for the user or can it be pulled specifically with a query and not after I get a response of all the data and use a loop to match Users Table primary key to the Comments table Users ID