Questions tagged as 'sql'

1
answer

Error: subquery returning more than one result

Given sql: DELETE FROM wgcartarmazens WHERE ( SELECT artigo FROM wgcartarmazens as T INNER JOIN wgcartigos as A ON A.CODIGO=T.ARTIGO WHERE T.lote='' AND A.TEMLOTE<>0 ); The above query returns me the following erro...
asked by 27.02.2014 / 16:45
4
answers

Sql - Query of two maximum values

Suppose we have this database codigo, data, valor,seq (1, '2014-01-01', 10,2), (1, '2014-01-02', 20,1), (2, '2014-01-03', 30,1), (2, '2014-01-05', 40,1), (2, '2014-01-05', 50,2), (3, '2014-01-06', 60,1); I want to get the most recent date f...
asked by 25.07.2018 / 04:41
2
answers

Update tables using trigger, from a main table

I have the following structure: A main table X, where the "header" of the sale is stored. A Y table, where sales items are stored. A Z table, where some sales data will be saved, from triggers fired from table X. In this, every time...
asked by 02.08.2018 / 20:41
1
answer

How to check if all the data in my list exists in the database?

I need to get the files that are in a list and compare them with the files that are in a table in the database, and know if the amount of files in my list is the same amount as the table. using Dapper; public bool ValidarPessoas(List <in...
asked by 13.06.2018 / 19:58
2
answers

Select the first and last day of the previous month

I have the following query : select ADDDATE(LAST_DAY(SUBDATE(CURDATE(), INTERVAL 1 MONTH)), 1) primeiro_dia, last_day(sysdate()) ultimo_dia That returns me the first and last day of the current month according to the system date. How co...
asked by 04.06.2018 / 14:29
1
answer

How to display records that have no referenced data in a query

I have 3 tables: Person CREATE TABLE Pessoa ( ID_Pessoa INTEGER PRIMARY KEY IDENTITY (1,1), ID_Telefone INTEGER FOREIGN KEY REFERENCES Telefone (ID_Telefone), Nome_PSOA VARCHAR(50) NOT NULL, CPF_PSOA CHAR(14) NOT NULL,...
asked by 04.06.2018 / 04:06
1
answer

Selection with LEFT JOIN

I'm studying sql and I do not know if this is possible. But I have the following tables: Table contatos ______________________ id | nome | sobrenome | ______________________ That only contains one contact: 1 | andrei | coelho...
asked by 24.03.2018 / 22:44
1
answer

MySQL event to block user with x complaints

I have a complaints table where I record the information of users who reported and who they reported id | user | denunciado 1 | userx | userY 2 | userz | userY And so on, now I would like to make a daily event in mysql...
asked by 14.04.2014 / 21:58
1
answer

Selection with Dapper using IN clause

My idea is to generate a search on my bank using the in clause through Dapper . For example: select * from product where CasNo in(@filtro) Remembering that within this @filtro has a list of CasNo that is of type List<...
asked by 22.10.2018 / 17:53
2
answers

Column 'discount' can not be resolved. How to use a column that is the result of a calculation to calculate another column in the same query?

I have the following query: Select price, col2, col3*7.5 AS desconto, (price*desconto) AS finalprice From tab1. When I run I get the following message: Column 'desconto' cannot be resolved . How do I resolve this error? Note: I'...
asked by 15.10.2018 / 19:29