Inner Join with repeated values

Asked

Viewed 60 times

0

Good morning! will someone help me with a question?

i have a select

SELECT * FROM order 
INNER JOIN kn_status ON (kn_order.n_order = kn_status.fk_order)
WHERE kn_order.fk_cliente='$id'

the problem is that in the table STATUS the N_ORDER is repeated several times and when I execute the WHILE it shows me the result of the repeated ORDER table.

  • 1

    It would be more valid if you showed what you have in the table and what the expected result

  • 1

    But how do you want to bring only 1 record and have several repetitions of it in the STATUS table? You need to pass another single 'parameter' in order to bring a single row. Your JOIN in the table structure is wrong in my view. You should have mounted the structure with an ID_STATUS (SINGLE) as a foreign key and not an order number that is not presented there. If possible post the table structure.

1 answer

0

Hello, David! This is a problem of structure. If the column n_order will be related to the column of another table, then it should be a single column (its objective). But if this is not the constraint, that is, the n_order column can repeat, then use the value differentiation column. This differentiation column is where it says that one row is different from the other.

Good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.