Questions tagged as 'sql'

2
answers

Query to return the first record with specific values

I have to perform a search of the first records with a certain value, let me exemplify. SELECT * FROM users WHERE gender LIKE '%M%' ORDER BY id DESC LIMIT 1; SELECT * FROM users WHERE gender LIKE '%F%' ORDER BY id DESC LIMIT 1; This gives m...
asked by 02.10.2018 / 18:51
3
answers

Duplication of code in Laravel ORM

I was working and I came across the following situation: if (($entrada == null) and ($parcela == null)) { $cotas = Produto::orderBy('credito', 'DESC') ->where('id_subcategoria', $subcategoria) ->where('visivel_site',...
asked by 04.01.2019 / 19:18
2
answers

I am having difficulty creating a database and relating 3 tables

I am having difficulty creating a database and listing 3 tables: return the customer's name and surname, your neighborhood, and the values of your movements, the date ordering the movements for this sql command to work SELECT ClienteNome, Cli...
asked by 06.12.2018 / 23:04
2
answers

Sort by the largest ID and group the similar ones

How can I list the records by sorting the last one, but when I have the field related filled in, bring the other records with that same value? The general idea is to make a order by id desc and group the related ones. My tabl...
asked by 03.01.2019 / 22:51
1
answer

How to convert 39 hours to type 'TIME'

To accomplish a certain task, I count the amount of time I spend on the task in my system. Today I came across the following: Data Inicial: 17/12/2018 16:49:14 Data Final: 19/12/2018 08:02:58 totalizando: 2362,29 minutos. Converto para d...
asked by 19.12.2018 / 11:43
1
answer

When firing an Update Trigger, one of the fields only refreshes after a second Update

I created a trigger to report the fine on the return delay of rented movies, however, when triggering the trigger once (giving an UPDATE), the "MultaTotal" field does not update (only it). But when the trigger is triggered a second time, the fie...
asked by 09.12.2018 / 16:27
4
answers

How to create mirrored temporary table in another

Is it possible to create a temporary table that is mirrored in another? Example: Let's say I have in my bank a table with 60 fields. I would like to create a temp named #tabela with the same structure as the table in the database, but wit...
asked by 19.04.2017 / 14:04
1
answer

Select a list of values and from this list, select the lowest value

I want to select the last 10 inserts of a table and among those 10, return the lowest value. Is it possible to do this in a single query? Selecting the last 10 values: SELECT id_relevo FROM relevo ORDER BY id_relevo DESC LIMIT 10     
asked by 23.09.2018 / 03:30
4
answers

SQL command too slow

SELECT funcionario.nome, foto.foto, count(*) total FROM venda, funcionario, foto WHERE venda.idfuncionario = funcionario.idfuncionario AND funcionario.idfuncionario = foto.idfuncionario AND gol = 1 AND ativo = 1 AND idsancall IN (5,7,8,42...
asked by 24.09.2018 / 19:54
3
answers

While inside another While (PHP - SQL)

I searched the forum and the internet, but I could not solve the problem yet! I am doing a query in the bank by PHP and looking for users. After searching the users I look for his academic formations within that other search (since there may be...
asked by 11.01.2016 / 13:02