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
answer67
viewsUpdate with JOIN with 2 tables together with Select
Hello, I’m with the following query to perform in a database but locked in a situation, below follows the query, the error message and then the explanation. Excerpt from the Code USE BDTESTE GO…
-
-1
votes1
answer55
viewsWhere to delete records that were entered a certain time ago
Help to create a delete with where if the record has been inserted for more than 5 minutes. I have the point marking table with the columns: cd_register - integer cd_enterprise - whole cd_matricula…
-
-1
votes1
answer64
viewsSQL - search data from different tables without relationship with Ids
Personal table (id, cnae, cnpj, ...) (amount of records 40M) Table cnae_secundario (id, cnae, cnpj) has no attachment by id with the personal table. (amount of 50M records) The user will inform the…
-
-1
votes1
answer38
viewsHow to update a select with sub queries that contain Group by and order by
Physical Table Registro IDBanco DataMovimento Credito Debito SaldoAtual Ordenado 1 26 2020-07-05 500,00 0,00 0,00 5 2 26 2020-07-03 0,00 10,00 0,00 3 3 26 2020-07-06 0,00 20,00 0,00 6 4 26…
-
-1
votes2
answers79
viewsSQL Do not display rows from a duplicate column
Hello guys I’m having a hard time not displaying the items of a duplicate column, in case the column C.CLI_ID, I need to show only the first result. I’ve tried several ways but SQL is not my…
-
-1
votes2
answers114
viewsAdvanced Firebird Join - I can’t join the tables I need and sort in the right result
Good evening guys. I’m on a quest that has been depleting my neurons for a week and I still can’t find the solution. In an ERP used by a client, the demand to visualize purchase value vs sale,…
-
-1
votes1
answer48
viewsQuery Problem C#/Postgres
I have the following method: private static List<ProdutosTmpModel> GetInListaPromo_caddespd(Dados dados, Empresa emp) { //busca todas os produtos das listas vigentes StringBuilder command1 =…
-
-1
votes1
answer109
viewsDelete repeats and return last Postgresql record
Good afternoon, I need to make a query to return the description of the records of a table, and there can be no repetitions of ID (of another table) and need to be the most recent record.…
-
-1
votes1
answer40
viewsProblems with SQL query with Knex in React
Next I have two tables one of Students and another of users and I am trying to make a simple login call by checking the user’s email and password through the foreign key between Students and user.…
-
-1
votes1
answer38
viewsElements of a PHP table appear repeated and others do not appear
I’m putting together a page to display the courses registered within Moodle. For this, I am doing local tests, where I registered 4 disciplines and 5 users. The intention is to display these four…
-
-1
votes1
answer39
viewsHow to perform this query correctly ? [Mysql]
In front of this database: Employee(employee, employee name, street, city) Works(employee, code company, salary) Company(code company, company name, city) Manager(employee,…
-
-1
votes3
answers376
viewsMYSQL Insert into com Where not exists
Staff I have the following situation, I have 2 tables, I need to insert in table B data that are in table A, however, should be checked if the data that are in table A already exist in table B, if…
-
-1
votes1
answer30
viewsPull only user items
Talk personal, I have 1 database and data with 2 tables so far the first table is responsible for registering the users with the name "users", the other table is where I want to register the events…
-
-1
votes1
answer38
viewsHow to know which lines are not in certain groups?
I would like to know which ids are not present in certain groups for a certain period of time. For example: SELECT id from table1 Results in the following exit: id 1 2 3 4 5 And the consultation :…
-
-1
votes2
answers51
viewsSQL Locates duplicate releases and brings another table data
Good morning guys! I’m not so experienced yet in SQL commands, so I’m looking for gurus here to give me a strength. Come on, I have a chart where they store deposit vouchers that customers send. We…
sqlasked 4 years, 2 months ago Alex Lacerda 1 -
-1
votes1
answer254
viewsjava.sql.Sqlexception: Column 'id' not found
My code to search in the BD by id. The class is ContatoDao: //Pesquisa por id public Contato pesquisaId(int id) { String sql = "select nome from contatos where id = "+id; Contato contato = null; try…
-
-1
votes1
answer66
viewsHow to insert an "if" into an INSERT string in the database?
I have the following variable DateTime ContaRecebeDataPagto = Convert.ToDateTime(dgOrigem.SelectedRows[0].Cells[2].Value.ToString()); She gets a value from DataGrid, in some cases the date of…
-
-1
votes2
answers83
viewsHow to make a CASE WHEN for named expressions?
Good morning! I’m having trouble making one CASE WHEN of a named expression. I have a SELECT in which one of the parameters has a named expression. Example:…
-
-1
votes1
answer335
viewsTime range between ORACLE SQL dates
Good afternoon guys, I have a question in oracle SQL in which to solve I wanted to get the following information: Before, I have this query: SELECT…
-
-1
votes1
answer42
viewsMultiple SQL column query - Laravel
Guys, I’m trying to make a query, where I have several fields to perform this search, and some null field may come. I’m using Laravel with Angular, I don’t know if I can do this consultation on the…
-
-1
votes2
answers20
viewsGrouping datatime in selects and summing the elements of the search per day to perform a comparison of the days of a given month
I’m using the type datatime and trying to perform a select that counts emissions day-to-day to mount a comparison chart of the days of a given month. However, when grouping the dates it is returning…
-
-1
votes1
answer35
viewsHow to dynamically assign a column name to a query using PHP PDO?
I’m trying to create a update query, in order to define the column name to be updated dynamically, but for some reason I cannot do this. Why? And how can I do that? My current code: //atualizando…
-
-1
votes1
answer34
viewsInsert into table leaving null the old record
Good morning, you guys! I have the following code below, where I am trying to save a value of kg per day, I am using as the basis the day without time, however when setting the value for any day,…
sqlasked 3 years, 11 months ago Renan Goulart 11 -
-1
votes1
answer83
viewsENCODE PROBLEM WHEN SEARCHING FROM THE ASP Classic (SQL SERVER)
All Asp pages are as UTF-8. I look for the title of a table in the database by passing by parameter(request), but when displaying always displays with Ncode problems, I use IE because of the system…
-
-1
votes2
answers34
viewsSub-consumption With Different Aggregate Results
Good afternoon, everyone, I have two queries that work perfectly separate, but need to display in a grid information of the two queries. I need to take all the inputs of a product and put in a…
-
-1
votes1
answer104
viewsScript for a particular SQL library
Imagine that a client contacted and requested the creation of a system to register the books of the private library, in your conversation with him you arrived in the following tables that the system…
-
-1
votes1
answer38
viewsInsert Multiple Data from a Dynamic Form into MYSQL
I don’t have much knowledge in PHP and I have a form where the user has some fields to fill and write in the SQL database, and a field of this form will be dynamic where the user can add as many…
-
-1
votes1
answer68
viewsCONDITIONAL ROW NUMBER
Good morning Everyone, I have a select column named "ROW" that starts a numerical sequence (1,2,3...[which sometimes can be more than 100]) when all columns that are Partition are equal, and when…
sqlasked 3 years, 9 months ago Carlos Gabriel 41 -
-1
votes1
answer31
viewsMy first script and I can’t fix the error
CREATE TABLE Aluno ( Id_Aluno VARCHAR(100) NOT NULL, Rgm NUMBER(8) NOT NULL, Cpf NUMBER(11)PRIMARY KEY, Nm_Nome VARCHAR(100) NOT NULL, Nm_Mae VARCHAR(100)NOT NULL, Nm_Pai VARCHAR(100)NOT NULL,…
-
-1
votes1
answer25
viewsSum of values according to value of another column
I have two doubts that are difficult for me but that maybe I can be simple for you. I wondered how I could make a sum of the amount according to the units that in this case would be the units…
-
-1
votes1
answer31
viewsdoubt max sql
I have a question about sql, to with a query that I want to bring the most recent answer of an object, only that is always coming the history, I tried sub query, and etc, max, but it did not work,…
-
-1
votes1
answer28
viewsQuestions with COUNT/GROUP BY
Good afternoon, I’m having trouble with the group by clause. I have a gigantic query, I need to quantify the contracts by Id, showing the degree of impact. Then I gave a Count(Id). The problem is…
-
-1
votes1
answer83
viewsI need to make a Select in 3 different tables and do not know how to do
Next I need to make a query in the following conditions: I need the table data A (Numero, Ano, vencimento, Nome); seeking the information of unwelcome in the column Recebimento table B; and I need…
-
-1
votes1
answer18
viewsHow can I count the number of Records in Mysql?
I have this Mysql code: SELECT COUNT( PEDIDO.COD_PEDIDO ) FROM PEDIDO JOIN PEDIDO P2 ON P2.COD_CLIENTE = PEDIDO.COD_CLIENTE AND DATE( PEDIDO.DT_PEDIDO ) = DATE( P2.DT_PEDIDO ) AND PEDIDO.COD_PEDIDO…
-
-1
votes2
answers92
viewsProblem in SQL search
I am doing an exercise where, for each name of a discipline, I need to return the number of students approved and failed. When I search for the approved and failed students separately, I get the…
-
-1
votes2
answers59
viewsError clicking button to save data to database
Good morning guys, I’m trying to save some data in the database, for a button of windows form C# and this error appears. I have tried everything but the error persists. I did the print and pasted…
-
-1
votes2
answers52
viewsDelete all items that have at least one Null value
I am needing to do a query that DOES NOT return the Ids of contracts that have ANY installments like Null, in the example below I need it to return empty, because the ID contract 666666 has at least…
-
-1
votes1
answer33
viewsSUBSELECT - POSSIBILITY OF IMPROVEMENT
I would like some guidance on a query. It is working, but the current script generates a very high reading demand in the bank due to a case comparing a table data, with another through a subselect…
-
-1
votes1
answer40
viewsHow to group the records by year?
How would I group the years that are equal? in my table there is a record with the year 2019, one with 2020, and 3 with 2021, but in time to show the result the records that are with the year 2021…
-
-1
votes1
answer82
viewsCount a pl/sql column
I am trying to count a column (minutes) as it is in the query: SELECT distinct b.nr_atendimento ,to_char(dt_prescricao,'dd/mm/yyyy hh24:mi:ss') Prescricao ,to_char(a.dt_atualizacao,'dd/mm/yyyy…
-
-1
votes1
answer45
viewsInsert INTO mysql and python error
When I try to make an INSERT INTO in my SQL code, it gives the same error mysql.connector.errors.DataError: 1292 (22007): Incorrect date value: '1998' for column 'validade' at row 1 This is my…
-
-1
votes1
answer24
viewsTake a variable from within a function
How can I get a variable from inside a function. my code: function buscaGeralPessoas($buscaPessoas){ $result_msg_contatos2 = "Select idGeralPessoas, cpf, nome, telefone1, telefone2, celular, email…
-
-1
votes1
answer46
viewsTrigger to prevent repeated data on ORACLE
Opa personal I am trying to create a Trigger to prevent the entry of repeated data in Oracle but am not succeeding. You cannot use Constraint Unique, because I will have repeated data, because it is…
-
-1
votes1
answer42
viewsUpdate with subconsultation and Inner Join - Mysql
Tables Contract id, contract, credit_id, debtor, evento_id, campanha_id Title id, contrato_id, title, maturity, value The idea is to update the field campanha_id of contracts using a sub-allotment…
-
-1
votes1
answer28
viewsExclusion of related tables
Good morning, I am trying to delete my user class but am having the following error "Cannot delete or update a Parent Row: a Foreign key Constraint fails (pitangdb.phone, CONSTRAINT…
-
-1
votes1
answer92
viewsSpecific join between tables
I have two tables customers id razao_social 1 company_1 2 company_2 and tasks id id_client tasks competency 1 1 '101' '032021' 2 1 '102' '032021' 3 2 '101' '032021' When I make one join between…
-
-1
votes1
answer30
viewsMysql - Count equal data in the same column
Good afternoon to all, I have a table called 'ms_msg_log'. In this table, I have the columns 'id_error' and 'data_alt'. I need the data displayed as follows: id_error = the normal value of the…
-
-1
votes0
answers19
viewsHow to do a Listview filter search in Flutter?
How can I make a filter for searching this code? import 'package:flutter/material.dart'; import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/intl.dart'; import…
-
-1
votes0
answers29
viewsSQL, as always bring a value in a query even though the query is null
I have the following select, in it I bring the point of operation on day 1, and the subquery brings the point of dia2. SELECT id_Ponto, (SELECT id_Ponto FROM ponto WHERE cancelado = false AND…
-
-1
votes1
answer45
viewsHelp with Select adding up accounts to pay and receive fields for MYSQL reporting
I have two tables equal fields, ACCOUNTS TO PAY and ACCOUNTS TO RECEIVE, I need to generate a report taking the value Credit - Debit and leaving result, someone can help me, I’m picking for this,…