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
-
0
votes3
answers444
viewshide id passed in url
is the following, in the application I am developing, I have a complaint form where the user does not need is logged in to fill it and make his due complaint, up to there everything right, so he…
-
0
votes1
answer79
viewsIdentify sequential records between a short period of time
I need your help to identify sequential records in my database in a short period of time Example: $qdt_acao_suspeitas = 5; //5 ações consecutivas $tempo = 10; //10 minuntos If user X performs the…
-
0
votes1
answer107
viewsExtract date in text column
There are other ways without use Regex to extract data of a text column in Oracle 19c. So far I managed using Regex as follows: select REGEXP_SUBSTR(p.observacao,…
-
0
votes4
answers68
viewsDoubt about Group by
using SQL Server I have made the following select to select products purchased by customers: select ITEMPEDIDO.IDPEDIDO, ITEMPEDIDO.QUANTIDADE, CLIENTE.NOME from ITEMPEDIDO, cliente, pedido where…
-
0
votes1
answer20
viewsHow to use the values of a column present in Table A as the WHERE parameter of a SELECT in Table B?
It is possible to make the SQL query $professores is made based on ID $row["id"] of the 5th line of the code below? Contextualizing: this code displays a list of courses present in a BD, printing…
-
0
votes2
answers34
viewsLogic for SQL statement - Sum of values between Table A and Table B
To table A is the table that receives several rows containing different values related to table B which is where the items are stored. Table A Descrição | Valor item 1 | 50,00 item 1 | 40,00 item 2…
-
0
votes1
answer69
viewsFind a best-selling item along with another
Find a best-selling item along with another. Sql server TABLE SALE CAMPOS = ttcupomfiscalitem PRODUCT TABLE FIELDS = ( tcproducts) I tried to make the following sqlserver query SELECT TOP (10)…
-
0
votes0
answers20
viewsPerform line offset(lead Function) by making the last line 0 instead of 'NULL'
I’m using correlated subsettes to simulate the LEAD function because my Mysql does not support this function, by scrolling the rows of a column. However, when moving, either through the original…
-
0
votes1
answer83
viewsComplete values in a table, with values of the table itself?
I have the table data ativo valor ajuste arquivo 17/07/2020 teste1 4,35 nan 9032800000190015197.txt 16/07/2020 teste1 nan nan 9032800000190015197.txt 15/07/2020 teste1 3,12 nan…
-
0
votes1
answer156
viewsSql Father and Children in the Same Table
I have the following question, I have a table in the bank that cannot be changed to facilitate the process. In this table I have records parents and children with the possibility of up to 8 levels.…
-
0
votes3
answers92
viewsError using case clause inside a Where
I’m having the following error in trying to use the case clause of a WHERE. ORA-00905: palavra-chave não encontrada 00905. 00000 - "missing keyword" *Cause: *Action: Erro na linha: 56 Coluna: 39 My…
-
0
votes1
answer37
viewsList table with increasing numbers with pagination
Hello, I’m doing a donor ranking, but I had a little problem I am wanting to list all users and want to organize by increasing numbers, ex: 1,2,3,4,5,6.. but when I go to the next page the numbers…
-
0
votes1
answer20
viewsNOT IN/EXISTS in more than one table in the same query
I have a table of employees and I need to extract from it a query of employees who are not registered in any of the positions (architect, landscaper and manager). The column COD of employee is the…
-
0
votes1
answer73
viewsRelationship with log table
Guys, guys, beauty?I have two tables from an oracle database: Fields in Table A: No. do chamado Data de conclusão do chamado Funcionario que concluiu Fields in Table B: Funcionario Area do…
-
0
votes1
answer71
viewsGroup By select
I have an Employee table with the fields Name, Age, Gender and Company. And each employee may or may not be in more than one company. With that I made the following select in this table. select…
-
0
votes1
answer30
viewsRemove SQL CASE parameter agreement results
As follows the query below, I need to remove from the SQL query the results that have the field CLIENTE_UNICO EQUAL TO 'MULTIPLE PURCHASES IN THE PERIOD'. SELECT NFE.CD_CLIENTE AS "COD. DO CLIENTE",…
-
0
votes0
answers27
viewsCreating a VIEW of a VIEW
I have the following problem in the company, where I have several panels that get information from a VIEW that does not have NOLOCK in the query. In order not to have to change each panel, it would…
-
0
votes0
answers23
viewsConsultation of Total General
I am with the need to build a query where I have the following situation Table 1- Sales [1]: https://i.stack.imgur.com/6GOO7.png In this table I have other vendor codes with other values. I am…
-
0
votes1
answer25
viewssubtraction of values between columns other than the same table
is the following, I am trying to get the result of a subtraction through a query between different columns of the same table. I have the following table. As you can see in the table, I have the…
-
0
votes1
answer230
viewsSpring Boot - initial test data
I am trying to pass data to test the front, but the controller is not getting the data that Spring Boot should start. My application.properties: spring.jpa.hibernate.ddl-auto=create My import.sql:…
-
0
votes0
answers233
viewsPostgres Pl syntax (syntax error at or near "integer")
I’m having trouble making a Pl in Postgres, I don’t know where I’m going wrong, can help me... THE TENACIOUS: do $$ declare id_cir integer; begin -- ERROR: syntax error at or near "integer" (SELECT…
-
0
votes1
answer44
viewsERROR: table name "mytableteste" specified more than Once
to try to do this query to "shuffle" the table data. This same query worked in mysql, but not in postgresql. always get this error [Code: 0, SQL State: 42712] ERROR: table name "mytableteste"…
-
0
votes1
answer25
views -
0
votes1
answer39
viewsList Database Result by Rows and Columns
I have the following problem, I need to create a report with data coming from the database, listed by rows and columns, in the format below: +----------+-----------+-----------+-----------+ | |…
-
0
votes2
answers56
viewsHow to return only the last maintenance line of each equipment?
I’m implementing the report module in a system I’m developing, but I can’t get where I want, my scenario: I have an equipment table, linked by foreign key to another table called maintenance, in the…
-
0
votes0
answers43
viewsMysql optimize Query
SELECT data_envio, nota_fiscal, nome_cliente, modelo.nome, conteudo.quantidade FROM conteudo, equipamento, caixa, pedido, cliente, modelo WHERE pedido.numero_pedido = conteudo.numero_pedido AND…
-
0
votes2
answers124
viewsHow to update some fields of a table
I am using the framework based on Java Scrit and Nodejs,Adonisjs.Need to update some fields in a table. Table fields user need to be changed, by default they come NULLS. The fields are…
-
0
votes1
answer268
viewsInserting in a python sqlite3 database by a class
I am doing a mini project of a registration in a database sqlite3 by python, my problem is that in my method, which registers the product with (id, name, purchase price, sale price, quantity), gives…
-
0
votes0
answers25
viewsFormat data from the same person in array. POSTGRES
I have an API that returns values to be plotted on a given graph Dashboard. However, this data needs to be formatted to fit the syntax of Charts.js. The consultation I’m doing is as follows: SELECT…
-
0
votes2
answers71
viewsHow to do WHERE with an incomplete name to find the record that in the bank is with the full name?
Hello, I need to get the system to email the registered person on a form as the engineer in charge. Then I need to make an SQL that looks for the email from the name. So far ok. If the person type…
-
0
votes0
answers45
viewsCreate function within MYSQL to change data in the same table
Hello. I have an application that inserts data into a table positions, in several columns, I need to take this data work them and write a new value in the column odo, that column the application…
-
0
votes1
answer170
viewsDoubt with Postgresql (Sum & Count)
Personal beauty? I’m studying SQL with Postgres and I’ve been doing well but I have an exercise to do which has swayed my head and I can not solve, and wanted you to help me not only by showing me…
-
0
votes0
answers113
viewsQuery in a SQL SERVER table
Hello, people. I need to make a query in SQL SERVER but the same is returning incorrect values. I have the following tables. In the proposed exercise I must return the following information: Extract…
-
0
votes1
answer205
viewsSQLCMD does not execute command after silent installation of SQL Server with Inno Setup
I have a script from Inno Setup which provides the user with the installation of SQL Server 2012, and upon completion, he should restore a database in a specified path, in order to 'componentize' my…
-
0
votes1
answer20
viewsHow to mount a sub-base with 7 tables?
I want to do a sub-query in my query with 7 tables, but I can only do with two tables. Code SELECT COUNT(cd_cliente) AS qtd_cliente, (SELECT COUNT(cd_funcionario) FROM funcionario) AS…
sqlasked 4 years, 1 month ago Matheus Santana 1 -
0
votes1
answer29
viewsit is possible to join one or more columns that have the same id in mysql
I have a customer table, a employees table, products, a sales table and a table to link sales with products. my doubt is when do I select SELECT idvendas,data_da_venda,valortotal,clientes.Nome as…
-
0
votes1
answer58
viewsDE_PARA SQL | Change table values based on information from another table
Good morning guys. Can you help me? I have previously researched elsewhere but could not find a viable solution. I need to change the data in the table below according to the new information. Data…
-
0
votes1
answer65
viewsCursor search: the number of variables declared in the INTO list must match the number of columns selected
Hello! I made a T-SQL and at the moment execute is giving the message: Message 16924, Level 16, State 1, Line 58 Cursor search: the number of variables declared in the INTO list must match the…
-
0
votes1
answer30
viewsmaximum hitNumber per visitID - google bigquery
I need to collect only the last hitnumber per visitID in a query from a Google database Analytics via google big query. Below follows my current code. I have reached the point of ordering the query…
-
0
votes2
answers53
viewsUnion of two selects presenting online
Below is a query performed for ORACLE database: SELECT ITOS.CD_NUMERO_OS, ITOS.DESCRICAO_RECLA AS "DEFEITO APRESENTADO" FROM GMITEMOS ITOS INNER JOIN GMOSERVI OS ON OS.CD_NUMERO_OS =…
-
0
votes1
answer32
viewsFind the year in which total customers (sum) was higher
I’m using sqlite, and I have a table like: year | clients ---- | ------- 2000 | 1 2000 | 2 1999 | 3 1999 | 5 2000 | 4 1999 | 6 This is just one example. I want to find the year when the total of…
-
0
votes2
answers50
viewsUPDATE REPLACE works on Phpmyadmin but does not work on Workbench
I can use this code on HphpmyAdmin: UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, 'src="https://www.meusite.com.br/wp-content/uploads/2014/07/tipo.gif" alt="Baixar" width="24"…
-
0
votes0
answers27
viewsSQL Query Clicking on the image that brings the selected color inside the input
I updated the server: the form has stopped working. The image fires an onclick, which switches the image on the form slide (this works); and informs the id/value of the selected color, which goes…
-
0
votes1
answer44
viewsDoubts about if clause
I have a problem in the query below: THERE ARE SOME DATA THAT ARE ON D1_NFORI, THAT MISSING "0" THE LEFT WOULD NEED TO INCLUDE THE ZEROS TO COMPARE IN THE WHERE EXAMPLE: Where IF D1_NFORI NOT LIKE…
-
0
votes1
answer279
viewsSql Server - Time Conversion (HH:mm) to Decimal
Hello, I am working on a system that requires conversion of hours to decimal and is showing error conversion from HOUR (HH:mm) to decimal when total hours exceeds 23:59. For better understanding if…
-
0
votes1
answer63
viewsHow to select from 2 id to bring Different Name
I’m having trouble making a SELECT on Postgres, as follows. Tabela -> Pessoa In this table, are stored data of Customers, suppliers, Exporters, Manufacturer, There is no table for each type of…
-
0
votes1
answer48
viewsError doing Count on Join
I’m having difficulties in an issue where my codes always go wrong. The question is: Select the customer name and the number of phones they have registered classified in descending order by the…
-
0
votes1
answer54
views"Fatal error: Uncaught Error:" in database
I’m running my first database (using a hospital as an example) through phpmyadmin, and the following error is being generated by attempting to register: Fatal error: Uncaught Error: Call to…
-
0
votes0
answers114
viewsError Parameter index out of range (1> number of Parameters which is 0)
I’m studying JDBC and learning how the resultset and statement, did first the method of adding and changing data with the statement that worked perfectly private void…
-
0
votes1
answer682
viewsConnect Sqlserver Localhost to Dbeaver? Connection Error?
I want to connect the Sqlserver Localhost in Dbeaver Manager. But trying it gives the error: The TCP/IP connection to the host mssql., port 1433 has failed. Error: "Este host não é conhecido…