How can I merge the rest of the data with the first query in SQL

Asked

Viewed 79 times

1

Personal I have a query in SQL that returns the values not duplicated column: Nº Tel, and that has the Status equal to TEMPORARY MALFUNCTION

SELECT DISTINCT [Nº Tel] FROM [export$] WHERE [Status] = "ANOMALIA TEMPORÁRIA"

I now need to join the rest of the columns that are in the same table [export] according to the result I brought from the first SELECT

The rest of the columns are:

  • [CPF/CNPJ]
  • [Number Contract]
  • [Reason for Sending]
  • [Activation Date]
  • [Date Import]
  • [Date Amended]
  • [Status]
  • And how does the first part join with the second part? Post example, so that we can understand.

  • Let me try to be more objective, well the first thing to do was to bring the non-repeated data, ok is done, but when I run this query: SELECT DISTINCT [Nº Tel] FROM [export$] WHERE [Status] = "TEMPORARY ANOMALY" It shows me only one column at [Nº Tel], I needed it to also show the rest of the columns, which are: [CPF/CNPJ] [Nº Contract] [Sending Reason] [Activation Date] [Import Date] [Change Date] [Status] ]

  • 1

    Magno, what you wrote in your previous comment is what was already in the description of the problem. I continue with the question "how to join the first part with the original table?". If you can directly add sample samples to the description (how they look; how they look after SELECT; how they should look in the end) make it easy to understand what you need. // You may not have noticed, but if there are two or more lines in the original table for the same phone, how to decide which one should be added to SELECT and which should be discarded? ;)

  • @Josédiz I apologize for not having clarified things well and not having given examples, but it turned out that I will stay only with that SELECT same, but I saw that you have enough knowledge with Database, and I asked another question and in it I explain right, give examples, and still put the query I tried to perform, if you can help me, because I really need, but my knowledge with Database is not so great, here is the link of the post: https://answall.com/questions/361821/howto verify datae-get it-first-record-in-sql

1 answer

0

SELECT
    MIN([Nº Tel]),
    [CPF/CNPJ],
    [Nº Contrato],
    [Motivo de Envio],
    [Data Ativação],
    [Data Importação],
    [Data Alteração],
    [Status]
FROM
    [export$]
WHERE
    [Status] = "ANOMALIA TEMPORÁRIA"
GROUP BY
    [CPF/CNPJ],
    [Nº Contrato],
    [Motivo de Envio],
    [Data Ativação],
    [Data Importação],
    [Data Alteração],
    [Status]
  • Actually this query is the same thing that I select the fields I need and that is with TEMPORARY ANOMALY, did not differentiate anything for me.

  • Are you sure, boss?! If this doesn’t solve your problem, then I don’t understand what difficulty you’re facing.

  • So, bro, I ended up with that same SELECT, but I asked another question here on Stack Overflow from another rule, there I am very objective, I demonstrate examples, and I also present an attempt that I made, if you can give me that strength, Thank you: https://answall.com/questions/361821/likeverifiingdata

Browser other questions tagged

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