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
-
-1
votes1
answer263
viewsRun Automatic Update - Oracle
I often run a Update on Oracle to change the status in my database, but I would like this update to run automatically, once a day. UPDATE inativa_produto set compras = 'N', estoque = 'N',…
-
-1
votes1
answer36
viewsHow to insert multiple Rows, where some Rows will have fewer values than columns
I’ll try to give a simple example of my problem. I have the following columns in a table called "Test": Name | Age | Gender | Nota1 | Nota2 | Nota3 I want to insert multiple lines in the table, but…
-
-1
votes2
answers687
viewsTOTAL row with the SUM of columns using PIVOT
Is it possible to do a row of TOTALS per column? The explanation of totals per row was fantastic and it turned out beautiful in my project. Thank you. My code: SELECT ano AS Ano, CCUSTOS AS [Centro…
-
-1
votes1
answer125
viewsUpdate add product from one table to another table
The query below it takes the product from the SALES table where it is equal to the product from the STOCK table and sum the quantity, it occurs that this query only works if it has 1 sales…
sqlasked 4 years, 8 months ago Anderson Ricardo 11 -
-1
votes1
answer389
viewsHow to make an INNER JOIN in a single table with 3 keys?
I have a table that has the following structure: origem|papel|campo018|campo040|mercado|Master_key| The column Master_key can have two values: 'NY' OR 'MS', I would like to compare the lines where…
-
-1
votes1
answer25
viewsWhat are the commands of a Superuser?
I would like to know what are the Rights that a Superuser has within a database. He can make what changes?
-
-1
votes1
answer48
viewsMake SELECT return only a snippet of the string
I need to make a query that only brings an excerpt of the string. I thought about using the SUBSTR() function but could not. Ex: column being something like [abcd efg hig; efg hig abcd; jkl juh hig]…
sqlasked 4 years, 7 months ago Feitosafelipe 59 -
-1
votes1
answer76
viewsSQL queries of state names with their number of cities
Good evening, I am starting to study SQL and I am making small queries in the database to practice. But I fall for the one that asks to display the names of the states with the respective number of…
-
-1
votes1
answer27
viewsI need to recover the sum of the highest values of each month
SELECT SUM(valor_parametros) FROM (SELECT valor_parametros,cnpj,data_movimento FROM (SELECT valor_parametros,cnpj,data_movimento,id FROM movimento GROUP BY MONTH(data_movimento) ORDER BY id DESC)…
-
-1
votes1
answer423
viewsRemove white space in select (SQL)
I wonder if you have any way to remove the blank space of the records returned in select. for example I have the NEIGHBORHOOD table with the records Bela Vista 'Amazonas' ' Gravel' but when I do…
-
-1
votes1
answer280
viewsReturn data from two identical tables [SQL] [Python]
Hi, I want a help with SQL query. There are two identical tables but with different recorded data in each one. How can I get the data from both tables? As if they were two selects in each table?…
-
-1
votes1
answer37
viewsSQL, search only one element per category
I am trying to make an SQL query that selects only one element per cat_id, from the genus of a cycle For where it checks if there is already a cat_id=1 and if you already have it goes forward until…
-
-1
votes2
answers28
viewsInput value equal to ID?
Hello, I have a table in postgres that has a column called link, serves to connect data with the same origin of several tables. This link is equal to the ID of the table in question 'tasks'. How do…
-
-1
votes1
answer85
viewsUsing the DATEDIFF
Guys, how do I make a condition with DATEDIFF deletes data from a table in 12 in 12 months? Example: You are in June 2020 - Then it erases everything before 01/06/2019. Another example: You are in…
-
-1
votes1
answer904
viewsFormat Firebird SQL data dd/mm/yyyy
How to convert a date to dd/mm/yyyy format in Firebird ? I tried some ways to convert 2020/06/22 to format but always come out in YYYY/MM/DD format: CONVERT(DATE, DATA, 103) AS "Data"…
-
-1
votes1
answer57
viewsHow to replace digits with "!" in SQL (postgresql)
Good Afternoon, I am trying in an output to exchange all digits in the address column for a '!'. I tried the following solution among others, but for some reason I’m not getting what I want. select…
-
-1
votes2
answers87
viewsHow to use rowCount to limit the number of records in a postgresSQL database using Node js?
I’m using the script to do this, but I get the error Internal server error. Anyone knows what I’m doing wrong? var sqlQtd = db.query(`SELECT COUNT (*) FROM segunda`, function(err, result){ return…
-
-1
votes2
answers861
viewsConnection to db SQLITE and SELECT * FROM reciclagem_data WHERE $variable
I am making a program that allows the user to enter the ID of the person in question and later shows in a table all the data of it. So far, I have these two codes: <!doctype html> <html…
-
-1
votes1
answer105
viewsDELETE IN SQL WITH WHERE STATEMENT NO ID REQUIRED
I have ZIP table with a new OP field with DEL information to delete. When I perform the instruction: DELETE FROM cepdb.log_bairro where BAI_OPERACAO = 'del'; Returns: 2 Cannot delete or update a…
-
-1
votes1
answer49
viewsRevoke Mysql ALTER TABLE command specific privileges 5.6.44
I need to prevent a column from being removed accidentally while running an Migration in a Mysql database v5.6.44, so I thought about limiting privileges, but even removing the permission of "DROP"…
-
-1
votes1
answer143
viewsTake the lowest values of a Count using group by
Cheers guys, I have the following problem... The query below is almost perfect, but it is generating repeated Ids, what I need is the lowest Count value of each ID. The ideal result would be: ID |…
-
-1
votes2
answers36
viewsDelete only if there is - in the word
I would like to delete some useless records from my database They are, for example: -2046820062 -2046820165 -2046820183 In short, all records that start with the symbol - (less) of my data2 column…
-
-1
votes1
answer471
viewsProblems connecting Node.JS Express in Mysql
I know my project is correct that there is nothing wrong, I think the problem is my newly installed bank, how can I solve this problem? Unhandled rejection SequelizeConnectionError: Client does not…
-
-1
votes1
answer25
viewsAPS.NET MVC - BD data split
I need to do a function in VB which allows to list in a Dropdown the data of a field in the database. I have to list the data from the 'Eixox' field (in the figure above) in the Dropdown. The doubt…
-
-1
votes2
answers2755
viewsSQL to load only part of a string
I’d like some help. I have the following query below, however, I need that in the DE column bring only the texts after the word "Exclusion", and in the PARA column bring only the text from the word…
-
-1
votes1
answer45
viewsI was able to search 1 more query in the database with PHP
I’m trying to do a search in my code, searching other fields, for example, looking for people who were registered with the mother’s name " so-and-so", but I’m not getting a logic... I can only…
-
-1
votes1
answer59
viewsWhich country had the largest total population each year
I created this table: CREATE TABLE `Populacao` ( `ano` int(11) NOT NULL, `pais` varchar(2) NOT NULL, `popM` varchar(10) DEFAULT NULL, `popF` varchar(10) DEFAULT NULL, ); Where popM is the male…
-
-1
votes1
answer33
viewsHow to add items from a column in SQL
I’d like to know how to add up those repeated items totaling their amount, I’m a beginner in SQL select Cardapio.Indicadorsetor, Service from Cardapio,…
-
-1
votes1
answer75
viewsHow many tables will you need in Mysql?
I’m starting a project that aims to manage students' grades and subjects. The information I’ll need to store is: Total subjects (All subjects the student will need to study) Current materials (These…
-
-1
votes2
answers47
viewsThe date of a sale changes when the record of the sale is updated
The column data_venda TIMESTAMP(0) of my table venda returns the current time of sale on my sales registration form. Only on an update form where I update the sale schedule changes, and I didn’t…
-
-1
votes1
answer18
viewsIt is possible to perform queries in a table that is not mapped by Hibernate
I would like to list data from a table that is not mapped by Hibernate; that is, I have an Endity map table and I want to report a search in a table in my database that is not an Entity. That’s…
-
-1
votes1
answer66
viewsSql, sum of several
Hello, I have a bank with 3 important tables, state,city and orders need to rank the states than have more requests to q have less but the orders are related only to city table. so I need to make a…
-
-1
votes1
answer25
viewsoperation with date and deadlines SQL_SERVER
I have a table in the comic book that has a column called term. in that column I have the deadline information in months ex.: 10, 6, 12, 14.... i would need to calculate to know the final date of…
-
-1
votes1
answer40
viewsSQL queries with multiple tables
I am studying SQL and needed to make a query, which for me is more complex. I have the following tables: Tabela Ativo: id, tipo_ativo Tabela Carteira: id, nome.. Tabela Movimento: id, ativo_id,…
-
-1
votes1
answer191
viewsORA-00904: Invalid identifier, I am creating a table but this error appears, could anyone help me?
CREATE TABLE CARRO( ID_CARRO VARCHAR(20), MODELO VARCHAR2(10), COR VARCHAR2(10), PLACA VARCHAR2(10), CONSTRAINT PK_CARRO PRIMARY KEY (ID_MARCA, MODELO), CONSTRAINT FK_CARRO_REF_MARCA FOREIGN KEY…
-
-1
votes2
answers44
viewsImprove select SQL Server performance
I have a table with 2 million records and I need to take 1000 by 1000, I know I can use TOP, but use the form below pq need to control the quantity, example: I get 1000 after the next 1000, then the…
-
-1
votes1
answer45
viewsSelect to calculate all records and total record by one condition
I have a sales table per user, which connects user_id, product_name and sales value. I would like to make an inquiry to return how many products were sold per user and how many products with more…
-
-1
votes1
answer23
viewsHow to search records until the previous month?
I need to get all the data, from the beginning to the previous month, this query has to be dynamic, I can not put a fixed date, because next month we need to consult again... In summary, today I…
-
-1
votes1
answer67
viewsHow to concatenate a result of a case with other fields?
Example: select x+y+ case when 2>1 then 'z' else 'w' end from table Expected result: Xyz The code above results in error. I couldn’t find anything like it... Admitting that they are all fields of…
-
-1
votes1
answer28
viewsI need to condition to bring in group by only the data that do not have a condition
I have the following query: SELECT id_grupo, id_analista FROM tb_grupo_analista GROUP BY id_grupo, id_analista; there is a third column called tp_controle, where I need to condition the query from…
-
-1
votes2
answers62
viewsDatabase Register
My database has this structure. I would like to know how to create the record on PEOPLE and at the same time get the ID and save it on PESSOAS_FISICAS. I created this command for such, but it didn’t…
-
-1
votes2
answers51
viewsHow to check if a character set exists in the table column?
I have the following table: |id|nome | |1 |Lucas Santos da Silva| |2 |Igor Julião Gonçalves| |3 |Mário Marques Silva | |4 |David Silva | How could I catch all the people who have Silva in the name?…
-
-1
votes1
answer23
viewsOperation of datiff in SQL 2014
I have an accumulated base of dates in sql, I wanted to select all dates you have from the current date (today) until 60 days ago, but I’m not getting the code right. ***select data CPF, sum(risco)…
-
-1
votes3
answers64
viewsHow to filter only numbers with 'Like' SQL
I have a table in which the field mainUnitId has the following data: Ad23 Ad7 Ad11 Ad9 Adv1 Adv14 Adv21 I need to bring in the search only those who have Ad + numbers after My code: SELECT * FROM…
-
-1
votes1
answer27
viewsVarious Inner Join with Where SQL
Hello! I’m new with sql, I’m trying to do two joins, but after putting Where in the first, it appears that the second is with syntax error, but if I take Where, or the second Join, it returns the…
-
-1
votes1
answer48
viewsWhy can’t I group data into that query?
SELECT e.idproduto codigo, p.descricaoproduto nome, sum(e.qtde) entrada, sum(s.qtde) saida FROM itementrada e INNER JOIN produto p ON e.idproduto = p.idproduto INNER JOIN itemsaida s ON p.idproduto…
-
-1
votes0
answers16
viewsSQL Server 1639 Installation Error
I went to login for the first time on the server and had an authentication error, uninstalled and went to try to install it again, only now it does not install the program. The Sqlserver process…
-
-1
votes0
answers7
viewsCould not find SQL driver
I give php Artisan serves and open localhost and return me: Illuminate Database Queryexception could not find driver (SQL: select * from sessions where id = 9MOM8bvIrofrPuP9POR5BpWIfDXFXkk0fd8jPDHT…
-
-1
votes1
answer29
viewsSQL Server - Function to format date field with Convert command
I have the following function: select convert(DATE,GETDATE(),101) Where she returns to me as follows: 2021-08-17 I want him to return me a data with this format "17/8/2021" keeping the data as date.…
-
-1
votes0
answers15
viewsSeparate DDD from phone with HIVEQL
I have a table with fields DDD and Phone. Some were registered correctly, others the ddd is next to the phone and need to separate. CURRENT TABLE: UPDATED TABLE: I am starting my studies in HIVEQL,…