Questions tagged as 'sql'

1
answer

How to set up a query with optional conditions?

In the example: SELECT * FROM exemplo WHERE ID in(2, 3, 4) It does if you have these ID in the bank. PHP: $id= implode(', ', $_GET['id']); $nome= implode(', ', $_GET['nome']); $cidade= implode(', ', $_GET['cidade']); $q...
asked by 04.08.2015 / 17:51
2
answers

Updating the structure of multiple databases in Azure

I have 5 SQL database ( Web Edition ) in Azure that should be exactly the same as the structure ( procedures , tabelas , views , triggers ... ) but the data is different. Can you update the bank structure in a more ag...
asked by 25.03.2014 / 19:42
1
answer

Using CTE (Common Table Expression) creates a type of "cache" in the database?

I have a query with several JOIN and sub-queries, and when executed, it takes about 7 seconds to return. Getting the same result, using CTE's, the query takes about 8 seconds of the first execution, but the next few times ( I could not...
asked by 20.11.2018 / 15:44
1
answer

Incorrect usage of UNION and LIMIT

I want my query to return only the first record of the first table (if there is data in it), because the second table does not have repeated data. But it returns me this error:    Error Code: 1221. Incorrect usage of UNION and LIMIT My...
asked by 22.11.2018 / 15:50
2
answers

Bring all records if parameter is different

I have a contrato table with the concluido field of type tinyint(1) , if it is 0 it is not complete and if it is 1 it is complete. I'm going to pass this value by parameter to the query, how do I get all the data when the val...
asked by 07.12.2016 / 20:27
4
answers

Mysql error 1054 Unknown column

I'm doing a SQL that counts how many names in the table begin with any letter but an error is being returned:    Column not found: 1054 Unknown column 'A' in 'where clause' For the following SQL: SELECT COUNT(*) FROM author WHERE name L...
asked by 27.04.2015 / 14:39
1
answer

Condition of a query with a subquery

I need to update the last 110 records of the relevo table, however my problem is in the subquery in WHERE . I'm doing it this way: UPDATE relevo SET id_projeto = 157 WHERE id_relevo = (SELECT id_relevo FROM relevo ORDER BY id_...
asked by 09.09.2018 / 00:50
1
answer

How to change multiple records in a sql table at once?

Imagine a result of an SQL: ID - NOME- MENSAGEM 1 / israel / msg-olamundo 2 / rafael / msg-olamundo 3 / augusto / msg-olamundo Now I want to do in SQL the same thing that str_replace would do in php to pull all records from one x to the wo...
asked by 20.08.2014 / 17:06
1
answer

Why when using ON DUPLICATE KEY UPDATE or REPLACE, do we have change in 2 lines?

Example When you execute any of the 2 commands, the message is returned:    2 row (s) affected Query : ON DUPLICATE KEY UPDATE : INSERT INTO 'banco'.'tabela' ('id', 'resumo', 'descricao', 'grupo', 'solicitante') VALUES ('1...
asked by 13.09.2018 / 12:09
1
answer

What is the cost of an update when it can not find the record?

I'm doing some SQL queries in my Delphi program and I had this doubt, what is the cost to the database engine when a UPDATE does not find the record according to the parameters of WHERE ? My question came from the need to make som...
asked by 09.03.2018 / 22:18