Inner Join returning duplicate lines

Asked

Viewed 148 times

1

I have a purchase order table, which relates to the products table, The purchase order table can own multiple products,

this consultation returns me all the purchase order, which has more than one product, duplicated.


SELECT *   FROM unisis.ordem_de_compra
        inner JOIN unisis.oc_produtos
        ON ordem_de_compra.id = oc_produtos.id_ordem_de_compra 
        
          where oc_date BETWEEN CURRENT_DATE()- INTERVAL 30 DAY AND CURDATE() and centro_custo = 'Balança'

the problem of the query is that example( if I have a purchase order with 3 registered products, it returns me as follows

id:25 customer: Alberto id_product: 1 product: a

id:25 customer: Alberto id_product: 2 product: b

id:25 customer: Alberto id_product: 3 product: c

I’d like her to return to me in the following manner

id:25 client: Alberto

id_product: 1 product: a

id_product: 2 product: b

id_product: 3 product: c

  • I believe that either something is missing or there is something too much in the ON clause of its conjunction.

  • 1

    What do you want to do with the query? What query is returning? Has error message?

  • ON ordem_de_compra.id = oc_produtos.id_ordem_de_compra and ordem_de_compra.id this line is wrong, the rest is missing after and

  • sorry really was wrong the consultation, I arranged

1 answer

0


Relational databases return result set (resultsets) which, in turn, have tuples, which are ordered data in what is conventionally called lines or records.

All lines have coordinates with origin and type defined at compile time. That is, if I write an SQL query to bring data from a table, it is exactly this query that tells me what are the data types of each coordinate and what are the columns where the data comes from.

--Tabela students(id PK, firstName string)

SELECT firstName, COUNT(firstName)
FROM students
GROUP BY firstName

In the above query, we have two coordinates per tuple: firstName, which is a table column students, and COUNT(firstName) which, ultimately, is an integer value that depends on whether firstName is null or not.

Thus, nay there is as an SQL query returns tuples of different types and origin depending on the line.

However, depending on the DBMS, you can get more than one result set under the same session. Search for more than one resultset, mysql on your preferred search engine for more details.

  • thank you attended my need

  • Please mark my answer as the best answer.

Browser other questions tagged

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