Questions tagged as 'sql'

2
answers

Catch only last query sql server query

I have the following query: SELECT CODIGO, DTINICIO AS INICIO, DTFINAL AS FINAL FROM PFHSTAFT WHERE EMPRESA =1 GROUP BY CODIGO, DTFINAL, DTINICIO It returns as follows:...
asked by 08.07.2017 / 00:03
1
answer

Catch all the data with the same id without knowing the id

I have a table in the database with information that has the same ID, as if it were a set, I would like to get all the information with this ID, but I do not have it, and I'm using a LIKE to fetch terms from this set, something like this: SELE...
asked by 22.06.2017 / 02:02
2
answers

How to do a select between dates [duplicate]

My question is very simple, I want to make a SELECT between dates, of a given table, where status='1' . That is, I have for example: $data1 = 13/01/2017 $data2 = 20/01/2017 I want to make a select of all results between th...
asked by 13.01.2017 / 22:25
2
answers

Left Join with multiple fields from the same table

To set up a lease, I have two tables. The first one is the contract, it has some relationship fields like id_locador , id_locatario , id_fiador1 , id_fiador2 , among others. These fields are related to a people table:...
asked by 11.01.2017 / 10:54
2
answers

SQL for last month and last two months

Hello. I'd like some help here. I need to get the records: MySQL Database 1) last month 2) last 2) 3) Current year SELECT id, data, lote, modelo, qtd FROM controle_diario WHERE modelo like ? The table is very simple: id is auto-increment,...
asked by 30.05.2017 / 13:56
1
answer

MySQL - How to get the name of the table where the result came from? [duplicate]

I have the following code in mysql: (SELECT * FROM entrada WHERE idUsuario = "1") UNION (SELECT * FROM saida WHERE idUsuario = "1") It's all working but I need to know which of the 2 tables came the result, how do I do it?     
asked by 09.02.2017 / 03:12
2
answers

Return pre-defined values depending on logical condition

I have the following script of MySQL: SELECT con.id_crecpa, con.id_crecpa, con.descricao, con.diabase, con.dt_emissao, con.dt_quitacao FROM crecpa con INNER JOIN pessoa pes ON con.id_pessoa = pes.id_pessoa INNER JOIN pla...
asked by 12.01.2018 / 23:18
1
answer

Select difficult with date [closed]

I can not do this: how do I return the time in minutes or hours that a particular VALUE occurred in the table below? Example: How long has the VALUE greater than "23" occurred on 05/05/2017? and if you have interval between records? for ex...
asked by 28.07.2017 / 02:39
3
answers

tried a query with union but did not get the expected result

I made a query with two selects using union and it has two columns: MOBI and DESMOBI . I need the result to show these two columns. when I execute it only shows the MOBI 'column. Below is the query. I look forwa...
asked by 02.08.2017 / 19:40
1
answer

SQL Exception Oracle - Update and Insert

I have a question regarding a procedure that I'm doing oracle database. A little explanation for what I'm doing: I'm reading data from a table, and playing them on a cursor, after playing the cursor, I set it to a record, in the procedure I have...
asked by 02.12.2016 / 15:17