Questions tagged as 'sql'

2
answers

How to remove rows from a table A that has no relationship with table B?

I have 2 tables and want to remove rows from table A that have no relationship with table B? For example: In table B I have a field FK_ID and I want to remove from table A all rows that have no relationship with table B, ie, it does not have...
asked by 25.01.2017 / 18:46
1
answer

How to group COUNTs for different queries in one?

I need to do a SQL query to count indications, I have the following querys : SELECT 'FACEBOOK', COUNT(id) FROM 'clientes' where indicacao like '%face%' SELECT 'Instagram', COUNT(id) FROM 'clientes' where indicacao like '%insta%' SELECT 'go...
asked by 24.11.2017 / 15:41
2
answers

Count how many fields are blank in a MYSQL row

I have a registration table with 53 columns (address, phone, etc.). I wanted to set up a query that would bring me how many of these columns are empty or NULL, how can I do this?     
asked by 11.10.2018 / 19:49
2
answers

PL / SQL anonymous block | ERROR PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

I get the following error: [Err] ORA-06550: line 7, column 2: PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: I'm using a create sequence inside my BEGIN with; and / but did not resolve the error. DECL...
asked by 13.09.2018 / 16:21
2
answers

Get current date in mysql

Colleagues. I have a table that stores the dates of the record with DATETIME (), but I need to check if the date of the record is equal to the current date, so I did it as follows, but it does not work: SELECT *,DATE_FORMAT(DataCadastro,'%Y...
asked by 01.02.2016 / 22:51
1
answer

How to mount SELECT in lambda C #?

Recently I asked for help to assemble a SELECT to bring the price of the products How to mount SELECT They gave me this solution that worked perfectly: SELECT P.PROCODIGO, P.PRONOME, H.HISPRECO FROM PRODUTO P INNER JOIN HISTORICO H ON...
asked by 16.02.2016 / 20:18
4
answers

How to select "1" or "2" depending on the column value in PL / SQL?

I have a column in my TIPOCLIENT table. In it appear CPF for Individual and CNPJ for Legal Entity. I would like the moment SELECT to come "1" to CPF and "2" to CNPJ. How can I do this?     
asked by 05.03.2014 / 12:40
1
answer

Is it a good practice to have the same name with the column name of the bank?

Let's say I have a input text de name="txtnome" , is it a good practice to have a column of the same name as this input in my table? Being that I'm using PDO for CRUD $st =$this->db->prepare("UPDATE $tabela SET yxtnome=:t...
asked by 11.05.2016 / 04:33
3
answers

Select 1 record of each ID based on the last date

I have a dummy TB_META table with the fields: COD_VENDEDOR | DAT_ATIVACAO | VAL_META Assuming I have these values in the table: 1 | 2011-01-01 | 1 1 | 2014-04-04 | 2 2 | 2012-01-01 | 3 2 | 2013-03-03 | 4 3 | 2013-01-01 | 5 3 | 2014-04-04...
asked by 23.07.2014 / 05:01
2
answers

SELECT displaying products except the results of another SELECT

I have this SELECT that takes the 6 best selling products: SELECT IdProduto, SUM(QtdProdutoPedido) as QtdProdutoPedido FROM tb_pedidoproduto GROUP BY IdProduto ORDER BY QtdProdutoPedido DESC LIMIT 6 I wanted a SELECT to show...
asked by 15.12.2017 / 19:56