Hey there =)

i have 2 tables with a relationship between them. a Primary key in the one table, and a secondary key referencing the primary key, in the second table.

Now usually when i want to display data in my db i INNERJOIN the two tables, so i can have the primary key and secondary key in one table to then use it to select certain fields... Buttt, i have a feeling that this isn't the correct way to do it.

And i have no idea how to write the query to select all fields in Table 2 where the secondary key is Equal to the Primary key. (without innerjoining them)

Do apreciate your help to improve my code.

Thank you =)

Ruan

The ANSI 92 standard allows for 2 ways to join tables: the declarative form (INNER JOIN, LEFT JOIN, etc.) and the equation form. These two statements are equivalent:

select table1.*, table2.* from table1 inner join table2 on table1.key = table2.key

select table1.*, table2.* from table1, table2 where table1.key = table2.key

For more explanation on join syntax for MySQL use this link:
http://dev.mysql.com/doc/refman/5.6/en/join.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.