leftJoin or Where to not bring info
leftJoin or Where to not bring info

Dear all,
I want to know if its possible to do something.
I have two tables, one is the main table and the other is secondary.
The secondary table has an ID column from the main table.
In a list I want to make, I want to show data from the main table that does not have any ID filled in as a reference to any row in the secondary table.
Is it possible to do this? Would it be through leftJoin or Where?
Tks in advance!
This question has an accepted answers - jump to answer
Answers
I'm a little confused
. You have a column in table A which references a column in table B, but some of the IDs that are referenced no longer exist in table B. Is that correct? That sounds like the referential integrity of the database is incomplete (perhaps it needs a foreign key constraint), but I would expect the join to resolve to
null
in such cases.Allan
I interpret this that those main table entries may not have a corresponding entry in the secondary table.
Then, what you want to achieve is this:
So you are doing a left join but you only want those rows from the main table that don't have a corresponding entry in the secondary table, i.e. the foreign key is null.
In Editor this should look like this:
Hello friends,
Sometimes I think that I explained very well, but this is dificult to me, hahaha, sorry!
I have table A like below:
| Table A
| ID_TABLE_A
| NAME
| DESCRIPTION
And table B like below:
| Table B
| ID_TABLE_B
| ID_TABLE_A
| NAME
| DESCRIPTION
Then what I need is that, on the list, shows only the lines from table A that don't have link to any line on table B on the field ID_TABLE_A
For example, I have ID_TABLE_A as 1, 2, 3 and 4 on table A, then on table B I have two lines that is filled on column ID_TABLE_A as 2 and 3, then I need to show on the list only the ID 1 and 4, excluding the ID 2 and 3 because there's lines on table B "consuming" these IDs
Ah yes, sorry. I missed that point and that it would need a filter to achieve it. Thanks @rf1234!
Allan
Thanks @rf1234, it's working