Most voted "sql" questions
Structured Query Language (SQL) is a language to query databases. Questions should include examples of table code and structure. This tag refers to the default language, not to be used for questions about the implementation of specific DBMS (such as Mysql, Postgresql, Oracle, MS SQL Server). In this case use the specific DBMS tag. Answers to questions marked with ANSI SQL should use SQL as much as possible.
Learn more…6,771 questions
Sort by count of
-
2
votes1
answer88
viewsHow to find the name and address of students and teachers in São Paulo
Hello, I have a question in the question that my teacher passed to train. The database has 5 tables being: a alunos, professores and historico in the exercise asks to consult name and address of…
-
2
votes1
answer1210
viewsSelect with subquery to catch previous record
I have a user readout log structure by reference. As shown below. SELECT L.LeituraID, L.UsuarioID, L.Referencia, L.Leitura FROM Leituras AS L |-----------|-----------|------------|---------| |…
-
2
votes2
answers188
viewsHow to update only one column of the record?
I made a code to update some columns of my record when needed. There are 7 columns listed on array, but usually I will only update 1 or 2 columns. With this code I can update my record, but I have…
-
2
votes3
answers3588
viewsHow to store more than one value in an "SQL variable"?
I work with a system that has a very limited report. The reports are basically restricted to one sql query. I need to present in a report a query that, in my query, is being informed by the user a…
-
2
votes1
answer45
viewsHow to sum the first 2 occurrences of a column using a key as reference in Sqlserver
Hello, I have the following table: create table events ( type int not null, value int not null, time datetime unique(type, time) ); Where in the same I have the following records:…
-
2
votes3
answers98
viewsWith LEFT JOIN list the NOT IN
In Mysql I have the table usuario, with the fields ID and CPF: I received from the client a list with some numbers and what I need: See which of these users is NOT in the table…
-
2
votes1
answer83
viewsJoin to Linq c#
I have the following query in Sql Sevrer SELECT PT.id, P.nome AS Codigo, PT.topologiaid, TE.id AS TipoEntidadeId FROM [dbo].[propriedade] P INNER JOIN [dbo].[propriedadetopologia] PT ON P.id =…
-
2
votes1
answer78
viewsConcatenation of Records via FOR XML PATH - SQL SERVER
Good afternoon dear, I have the following problem: I am developing a Query where I need to verify which documents were delivered by the student, documents that are in the table pre_matricula_doc and…
-
2
votes1
answer49
viewsProblems with Mysql query
<form method="POST" class="w-100" action="pesquisa_diaria.php"> <div class="card-body"> <div class="row"> <div class="col-sm-3"> <label>Tipo de Venda</label>…
-
2
votes1
answer56
viewsHow to return table values using the SUM() function?
I have the following tables CREATE TABLE tbCliente ( ClienteID INT IDENTITY(1,1) PRIMARY KEY, ClienteNome VARCHAR(50), ClienteTelefone VARCHAR(15), ClienteDataCadastro DATE) CREATE TABLE tbPagamento…
-
2
votes1
answer147
viewsGroup empty case when sql cells
I am making a query in the database to know in which branch the customer paid a installment and what is the normal value and interest that were paid. The value of the tranche is transaction 3 at the…
-
2
votes1
answer116
viewsHow to convert 39 hours to 'TIME' type
To accomplish a certain task, I count in my system the time spent of the respective task. Today I came across the following: Data Inicial: 17/12/2018 16:49:14 Data Final: 19/12/2018 08:02:58…
-
2
votes1
answer361
viewsError trying to import . Bak file from Sql Server on Linux
I am very beginner in SQL Server and am trying to import a file . Bak from a backup that came from another server (Windows) on Linux (Linux Mint 19) The command I used in the terminal was that:…
-
2
votes1
answer70
viewsList users' phones from a Join without duplicating lines
Good night, Guys, I have the following problem: I need to make a Join in two tables, USER and CONTACT. Each user has more than one contact (Phone), so when I list the data he returns me lines…
-
2
votes2
answers66
viewsDoubt about filtering a Query in SQL
As I can filter a Query so that the "Customers" do not appear with more than one phone, which in case would be Carlos as follows the image below. I’m breaking my head and I can’t find anywhere on…
sqlasked 5 years, 10 months ago Paulo Sergio G.M. Filho 141 -
2
votes1
answer66
viewsAssistance with SQL
Guys I have the following problem... I have a table XXX that has the following fields: k803, codrer, periodo, meta, challenge. The table shows the goal and challenge of each store representative 802…
sqlasked 5 years, 10 months ago Alexandre Prezzi 89 -
2
votes1
answer86
viewsQuery to update field from one table based on another
Good morning, I need to update the values of one table based on the values that are in another. I need the first table to update only the data contained in the second, for example, in the first…
-
2
votes1
answer1343
viewsHow to change 2 or more columns at the same time in Sql Server 2014? (ALTER TABLE/ALTER COLUMN)
How do I change 3 columns at the same time in the SQL SERVER table? I want to change the COLLATION, but it could be something else. I tried to: ALTER TABLE dbo.SIX_POSTO ALTER COLUMN VIS_DS…
-
2
votes1
answer84
viewsSum of values of a bd column between a time interval - PHP
include "conexao.inc"; $sql="SELECT * FROM tb_abastece WHERE data BETWEEN ('20/01/2019') AND ('30/01/2019')"; $res=mysqli_query($conexao,$sql); while($vreg=mysqli_fetch_array($res)) { $id=$vreg[0];…
-
2
votes1
answer90
viewsCreate recycle bin table
I have the database tables to store the data, but I want to add one to save the data of deleted rows from the other tables, I thought of four ways to do this: Create a table lixeira that will save…
-
2
votes1
answer68
viewsPerform table grouping with two parameters
good night. I’m still learning database and would like to ask a question with you. I know that if I want to organize my table with the invoiced values per month, I can use group by and filter it…
-
2
votes2
answers59
viewsnonexistent origin registration. How to bypass? Foreign Key
I have a field in a table of celulas who asks for the number of celula that gave it origin. Example: We have the table celulas: idCelula, nome, etc ... origem That one origin ago reference at the…
-
2
votes1
answer1508
viewsSQL Server Connection - Python
Good afternoon guys I’m having trouble making a connection with sql, whenever I try to make the connection the following error occurs: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL…
-
2
votes1
answer41
viewsA field in table 1 related to 2 fields in table 2
Let us suppose two tables Table 1 : emp (table of employees) Campos : emp.no (chave privaria), emp.name (chave múltipla, não primaria) Table 2: webConference Campos: webConferencia.no (chave…
-
2
votes2
answers1212
viewsAdd sold quantity of all SQL products
I have two tables in a Select through an INNER JOIN, I would like to know what I did wrong so that is displayed the list of products of all sales and the total amount sold of each product..…
-
2
votes1
answer68
viewsCase/when, help us
I did a search and I couldn’t find a logic to use in this case. the table columns are: COD_DO_USUARIO_ONE | COD_DO_USUARIO_TWO | TEXT I’m basically trying to put together a code that can identify…
-
2
votes0
answers55
viewsQuery return interaction with Array
SQL: SELECT t.idMembro, t.nomeTabela from ( SELECT idMembro as idMembro, 'pastores' as nomeTabela FROM pastores union SELECT idLider as idMembro, 'redes' as nomeTabela FROM redes union SELECT…
-
2
votes3
answers133
viewsSUM of one table minus the SUM of another in the same field
Hello, I am self-taught and already do some consultations in SQL but "stuck" in this. I need a list where one of the fields should show the total of a column, minus the total of another that is in a…
-
2
votes2
answers120
viewsLimit INNER JOIN query to only one ID
I’m performing the following consultation: SELECT enquete.image, enquete.status AS status_enquete, enquete.id AS id_enquete, enquete.title AS titulo_enquete, perguntas.id AS id_pergunta,…
-
2
votes1
answer342
viewsMsg 207, Level 16, State 1 and Msg 4413, Level 16, State 1 error
When I try to execute the following query, these two errors appear to me: Msg 207, Level 16, State 1, Procedure V_RECLAMACOES, Line 3 [Batch Start Line 0]Invalid column name 'Reason'. Msg 4413,…
-
2
votes0
answers41
viewsHow to add two result fields in a query already formed in SQL
I need to add two fields in a query already existing in SQL SERVER, but I don’t know how to add them in an existing query. I will try to detail more what I want with the images below: I have this…
-
2
votes1
answer1424
viewsOracle SQL Developer Table Creation
create table socio ( id_socio integer Not NULL, nome varchar(256) not NULL, cpf varchar(11) not NULL, email varchar(256), id_situacao integer, constraint socio_id_socio_PK primary key(id_socio),…
-
2
votes1
answer1776
viewsRegular expression for e-mail validation with REGEXP_LIKE on Oracle
I am trying to introduce an additional validation in my regular expression in Oracle 11G using the REGEXP_LIKE. I want the expression to detect two consecutive underscores but to ignore if they are…
-
2
votes1
answer255
viewsMysql - Update on every Row
Guys, I’ve been trying to put together a line of code for a while, but I never get the desired result, ever arrived in 3 codes but none of the 3 executes the code for each result found. It is…
-
2
votes1
answer57
viewsChanging tags automatically
I am creating a function for sending email via nodemailer, and our have some templates that are for specific cases. I need a function that once you receive the Welcome template for example,…
-
2
votes1
answer194
viewsScript to determine a desired column
Good morning! I’m trying to make a script where doing 2 joins, it shows me 3 columns. I mean, what I want is to get the email do lider. However it does not have a specific column, it is inserted…
-
2
votes1
answer51
viewsDelete duplicate rows in a table
I used the following SELECT to find the repeated values: SELECT nome, Count(nome) FROM projeto GROUP BY nome HAVING Count(nome)>1 Now I need to delete everything that is repeated and leave only…
-
2
votes2
answers120
viewsOracle SQL - Return of the first record between two dates
I have this query: SELECT codigo_usuario, dataproducao FROM tbproducao WHERE dataproducao >= to_date('01/02/2013', 'DD/MM/YYYY') and dataproducao <= to_date('30/03/2013', 'DD/MM/YYYY') and Is…
-
2
votes2
answers475
viewsSQL - Bring the name of the city with the highest number of sales
What would be the Mysql query to bring the city name with the highest number of sales? CREATE TABLE `clientes` ( `Codigo` INT(11) NULL DEFAULT NULL, `Nome` VARCHAR(50) NULL DEFAULT NULL, `Cidade`…
sqlasked 5 years, 8 months ago Leandro P. 23 -
2
votes1
answer135
viewsMore elaborate queries in Mysql
I have a problem in my application have the following tables Responsavel: id | responsavel_email 1 | joã[email protected] 2 | [email protected] 3 | [email protected] 4 | [email protected] Aluno: id | nome_aluno…
-
2
votes1
answer81
viewsRemoving data with TRUNCATE wouldn’t be DDL command?
Reading the OCA Oracle Database SQL Exam Guide(1Z0-071) I came across the following definition for the TRUNCATE on the topic of DDL(Data Definition Language): Removes all the Rows-in other words,…
-
2
votes1
answer250
viewsView much slower than direct mysql query
Good afternoon, everyone, I’m migrating a Delphi/Firebird system to Php/Mysql, And I’ve come across a situation I can’t understand, I created a view in mysql to generate a report, the same view I…
-
2
votes2
answers75
viewsI cannot insert the data into the sql table with a form
I am editing a wordpress plugin, and wanted with a form that I made the user when filling the form and the data were entered in the database I already have code but something does not work, could…
-
2
votes2
answers68
viewsQuery is not updating null values
I’m analyzing the data from a student database, the data is entered by the users themselves, and I can’t change the format of the tables and the database itself, just modify the values of the…
-
2
votes1
answer671
viewsSQL save and return Base64 image
I am saving an image in SQL Server using the varbinary field(max). However, when I run the query to return to the front, I can only return by converting the field to sweep. My question is how to…
-
2
votes2
answers66
viewsSee table by period
I have two tables, "Contact" and "Pedvenda", how can I make a query that manages during a period, for example, from 01/01/2019 to 30/01/2019 the quantity of sales between 10:00h and 16:00h each day…
-
2
votes1
answer206
viewserror when connecting mysql with Node.js
am connecting mysql with Node but is giving this error: C:\E. S\dao.js:10 if (err) throw err ^ Error: getaddrinfo ENOTFOUND localhost:806 localhost:806:3306 at GetAddrInfoReqWrap.onlookup [as…
-
2
votes2
answers432
viewsSelect from multiple tables with the same ID in Mysql
The intention of the query is to select all records of various tables when the ID is equal to the one passed in the parameter, echo of the SQL line displays the query below, the records exist, but…
-
2
votes2
answers548
viewsHow to use Mysql SELECT + WHERE + IN with Javascript array?
How can I perform the following SQL query by passing a Javascript string array? SQL query performed in Mysql - status OK: SELECT * FROM tab_price_list AS PL WHERE PL.PartNumber IN ('HDW00008.ELEM',…
-
2
votes2
answers112
viewsHow to select 2 records in an SQL Table in a given sequence?
I have a table with 100,000 records and the fields: id | dia | chuva_manha | chuva_tarde | chuva_noite I would like to create an instruction that consults the table and counts how many times a given…