Questions tagged as 'sql'

3
answers

How to compare the field of a current record with the next, in order to know if it is repeated or not?

I have the following query: SELECT pa.codigo, @rownum:=@rownum+1 AS nro FROM presupuestosa pa , (SELECT @rownum:=0) r WHERE pa.obra=18 AND pa.empresa=1 ORDER BY codigo ASC I wish that for each repeated code field, I can save the value 1...
asked by 29.07.2018 / 23:22
1
answer

Join tables with JPA

I request your help because I need to make a union of two tables in a query in order to create a list, but I do not know how to do it, this is the query that you create: SELECT p.id, p.nombre_departamento, p.ciudad_departamento,...
asked by 15.05.2016 / 17:57
2
answers

SQL statement to find a last record per customer by date

I am trying to create a statement that returns a field from a date, but under a certain condition. First of all I have a table with several fields, among which I am interested in the following image: What I need is for you to return...
asked by 05.03.2018 / 15:55
4
answers

How can I join these two queries?

select Nombre, sum(Compras_Productos.Cantidad) as Cant_adq from Compras_Productos, Productos where Compras_Productos.Id_Producto=Productos.Codigo order by Nombre select Nombre, sum(Ventas_Productos.Cantidad) as Cant_vendida from Ventas_Productos...
asked by 30.09.2018 / 03:15
4
answers

Optimize a query with a repeated subquery of MySQL

I have the following query SELECT * FROM TABLA_A WHERE CAMPO_1 IN ( SELECT CAMPO_X FROM TABLA_B ) OR CAMPO_2 IN ( SELECT CAMPO_X FROM TABLA_B ) The query works, I hope you can optimize the call of in since they are equal. I have...
asked by 28.09.2016 / 00:39
3
answers

How can I know how many times a data is repeated in an sql query?

Good afternoon I want to know how to get the number of times that a type of data is repeated and take it to a table with php at the moment I have the following code but I do not know how to extract the number of times that a data is repeated in...
asked by 23.09.2016 / 22:35
2
answers

Emulate subquery without main table in Access

I can do this in SQL Server: SELECT 'HERRAMIENTA ELÉCTRICA' AS TIPO_PRODUCTO, 0 AS DEPRECIACION, (select sum(empid) from HR.employees) STOCK But in Access the same query returns the following error:    Query input must contain at least o...
asked by 15.12.2015 / 07:53
2
answers

INNER JOIN 1 primary field to several foreign fields in the same table

I request your help to improve an SQL query. There are times when I have a table I want to relate several foreign fields to a primary field of another table, but the problem is that there is more than 1 field with a foreign key. Something...
asked by 12.10.2018 / 21:12
2
answers

what does NOT mean in UPDATE SQL?

Search Google and I can not find an answer for this, it seems easier to ask here. UPDATE table SET Paciente = Juan Perez WHERE RowID IN NOT (1,2.3)     
asked by 18.09.2016 / 06:22
1
answer

A method name is expected C # Load SQL data

using (SqlConnection cn = new SqlConnection ("Data Source = ACER-E5; Initial Catalog = mantenedorclientes; Integrated Security = True")) { cn.Open (); SqlCommand cmd = new SqlCommand ("Select rut,nombre,apellidop,apellidom from clientes...
asked by 10.10.2018 / 03:03