Questions tagged as 'sql'

2
answers

Changing the order of the Sql columns?

Good morning Could you instruct me to change the order of the columns in a table? Example: I have Table IcmsMvaUF in the following order: I'd like to pass the MvaEmpresa column to the first column on the left side of the...
asked by 25.05.2017 / 16:38
2
answers

how to do this query sql

code is PK in both tabela1: cliente codigo, nome, municipio tabela2: notafiscal codigo, numerodanota, cod_cliente I want to list a count (*) on all notafiscal where cod_client.municipality = 10 How do I run this sql?     
asked by 12.07.2017 / 21:45
2
answers

SQL query with PHP array [duplicate]

I have an array that will be variable, eg $ ref = array ('123', '654', '555'). I wanted to do a SQL query to bring information from these references, something like: SELECT * FROM tabela_itens WHERE ref = (array do PHP) How can I do th...
asked by 02.05.2018 / 19:56
4
answers

Add and subtract value from the same SQL column

I have a table with the following data: +---------------------------+ | Cod_Art | Armazem | Quant | +---------------------------+ | 11430001 | 1 | 0 | | 11430001 | 2 | 3 | | 11430001 | 3 | 0 | | 11430001 | 4 |...
asked by 12.01.2016 / 19:20
1
answer

Pivot dynamic columns

I need to display this: So: Following the link's instructions: Using the PIVOT operator without aggregation I can not place a subquery inside the IN in PIVOT Dynamic Pivot with SQL Server I came to this script: create t...
asked by 16.12.2014 / 20:00
1
answer

When should I create a constraint as DEFERRED?

As far as I know, creating a constraint (such as a foreign key or a check) as DEFERRED causes it to only be validated at the end of the transaction. Why is this used? And when should it not be used?     
asked by 18.03.2015 / 13:24
2
answers

How to print the SQL statement being sent to the bank?

I would like to know how to write a SQL for control purposes of the statement being sent to the database: $sql = $pdo->query("SELECT * FROM imovel WEHRE CATEGORIA = 'APARTAMENTO'"); How to print the SQL statement being sent to the bank?...
asked by 03.10.2014 / 18:34
3
answers

Specifying fields I do not want in MySQL

In MySQL, when we are going to make a SELECT , we can usually specify each field we want to return. SELECT id, nome FROM usuarios However, let's imagine a scenario where I have 50 columns in a table and I did not want the senha...
asked by 09.02.2015 / 15:04
2
answers

How to make a select in the bank to not bring repeated values?

For example you have in the table the values: green, red, blue, blue, pink, pink, pink, yellow. I would need to return from the table colors only once blue and pink. Do you have any way to do this?     
asked by 14.07.2015 / 19:33
3
answers

How to do update with count in SQL Server?

I have the following table: Nome | Posicao Item1 | NULL Item2 | NULL Item3 | NULL I would like it to look like this: Nome | Posicao Item1 | 1 Item2 | 2 Item3 | 3 Sorting criteria is Name     
asked by 03.09.2015 / 21:11