Hi, I'm not sure how I would query my DB with the use of the keys. My table will reference the username column in another table. The question is, can I call on the username column through the foreign key?
a foreign key basically just ensures a relation between two the data of two tables. in other words, you can't have one without the other. if one doesn't exists, the query will fail. you would need a join to access the the data on the related table. in my example we have two tables. tbl1 and tbl2. tbl1 has 2 columns, tbl1.id and tbl1.foo while tbl2 has 2 columns.. tbl2.id and tbl2.bar so basically this is saying select tbl2.bar where tbl2.bar = 'something' and then using the tbl2.id return tbl1.foo with the related id. select foo, bar from tbl1 left join tbl2 on tbl2.id = tbl1.id where tbl2.bar = 'something' Code (markup):
So, even if I establish a primary key in one table, and reference it with a foreign key in another table, I still have to create a join between the tables, to access their columns respectively? I mean, I can't just set up a primary key, and use the foreign key, to acces that tables data?
Ok thanks, but do these temp tables last only as long as the connection or what? Also can I join 2 tables that do not have a matching column? And, how do I call on the temporary table, so that I can run a query on it?