Questions tagged as 'sql'

1
answer

Select random ID between 2 and 4

Is it possible to randomly select the ID, for example by entering ID numbers that can be drawn (2/4)? Note: Only one line of this selection should be returned. I put this code but it was not: SELECT descricao FROM TABLE ORDER BY RAND I...
asked by 18.10.2018 / 06:34
1
answer

Field condition with subquery

Select example: SELECT campo1, (ROUND(((t3.quantidade * t2.distancia * (SELECT TOP 1 valor FROM frete WHERE datainicio <= t1.dataemissao AND tipo = t4.tipo ORDER BY DATAINICIO DESC)) - (t1.fretevalor - t5.pedagios)) / (SELECT TOP 1 valor FR...
asked by 08.08.2018 / 20:43
2
answers

SQL Parameter in PDO PHP does not work

The following code returns 11 bank records: $dbh = new PDO('sqlite:db_coleta.sqlite3'); $sth = $dbh->prepare('SELECT * FROM ROTA_VIEW WHERE usuario_id = 1 AND 0 = 0'); $sth->execute(); $red = $sth->fetchAll(); var_dump($red); But...
asked by 07.08.2018 / 14:42
1
answer

SQL JOIN multiple tables

I have 4 tables that I need to extract the results, but I always get duplicate records, can anyone help? tabclientes: codcli nome 1 A 2 B 3 C tabrepre: codrepre nome 1 AA 2 AB 3 AC tabvendedor: codr...
asked by 10.07.2018 / 23:00
2
answers

Inner with 3 tables PHP / SQL

I have 3 tables and I want to compare the value of them, I can do with 2 using JOIN , but when I put JOIN on the third
asked by 05.09.2018 / 17:04
1
answer

Error: SQL Server String or binary data would be truncated

I have the variable @numero1 which has the following result:    020000000000720000018 But at the time of the update it gives the error:    SQL Server String or binary data would be truncated declare @g1 varchar(50) declare @n...
asked by 29.08.2018 / 19:44
2
answers

Update using values contained in another table

How can I do an update on a table by setting the value of a field with the same value contained in another table for all records? I have a 'product' table and a 'mov product' table. I want to update the information related to the cost price i...
asked by 29.06.2018 / 14:06
1
answer

Use ON UPDATE CURRENT_TIMESTAMP when changing specific field

Example scenario Table: usuarios Fields: id , nome , sobrenome , senha , timestamp_alteracao Question The timestamp_alteração field should only be updated when the senha field chan...
asked by 28.11.2018 / 12:29
2
answers

SQL Query to select student and student name

I have this simple relational model, and I need a query that selects the student and the student's name.     
asked by 13.05.2018 / 00:34
1
answer

Storing Variables of type List in a SQL Server Database

Good Night Personal, I'm developing an application that makes a relationship between a Player and one or more games (online games), the problem is that a game can have a one more different skills, I wonder if you have a way to leave the new d...
asked by 09.05.2018 / 03:42