Imagining a scenario where:
Table1: id (primary key of table 1), id_2, name, CATEGORY (new
field)
Table 2: id_table 2 (primary key of table 2), id_2 (of table 1),
name, CATEGORY (new field)
A query in these two tables using the category for comparison would look like this:
SELECT *
FROM Tabela1 T1, Tabela2 T2
WHERE T1.id_2 = T2.id_2
AND T1.CATEGORIA = T2.CATEGORIA
You always have to treat the relations between primary and foreign keys in an SQL query.
But, if you remove the foreign key would look like this:
Table1: id (primary key of table 1), id_2, name, CATEGORY (new
field)
Table2: id_table2 (primary key of table 2), name, CATEGORY
(new field)
SELECT *
FROM Tabela1 T1, Tabela2 T2
WHERE T1.CATEGORIA = T2.CATEGORIA
Just remembering that if the fields allow null values your query would change.
But I guess I could tell.
Abs.
Why are they negatively?
– user7261
Just an @Andrey guess, maybe there are colleagues who unfortunately think that a basic question does not deserve recognition, even if it is such a common one. It is possible to reference almost any column (not blob), even if it is not unique! But if you are referencing an ID that is not PK revise your schema, if you are referencing one that is not even single review three times and call colleagues for a second opinion. Tip: Don’t forget to cover the column referenced with an index if there is no index
– jean