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
votes0
answers22
viewsQuery Sqlite3 tables using python3 and insert the results in a Treeview in Tkinter
The purpose of the code is to do Sqlite3 searches between two dates and insert these Tkinter Treeview searches. I have the second table in sqlite3: CREATE TABLE "MOTO_PALIO" ( "cod" INTEGER, "data"…
-
0
votes1
answer99
viewsMYSQL - TRANSACTIONS
Good evening, I’m a beginner in mysql and I came up with the following question. When I make a transaction like this START TRANSACTION ; INSERT INTO PESSOA2(IDPESSOA,NOME) VALUES(NULL,'PEDRO2');…
-
0
votes1
answer59
viewsI would like your opinion about an Entity-Relationship Diagram of a POSTGRESQL script
I am doing a work of the college whose goal is to make a database of a particular library and to elaborate an entity-relationship diagram of it , I made the script in postgresql but I have a lot of…
-
0
votes0
answers223
views#1452 - Cannot add or update a Child Row: a Foreign key Constraint fails
Personal talk I am having problems to create a foreign key in another table... You are giving this error: #1452 - Cannot add or update a child row: a foreign key constraint fails.... Follow the…
-
0
votes0
answers27
viewsError installing SQL server - Linux Mint
I already have flask installed on my NOTEBOOK with Linux Mint, but still no module called flask is showing up along with dpkg error. I tried various solutions on various websites such as: sudo dpkg…
-
0
votes0
answers124
viewsDivision by zero in PLSQL
Hello. The Code below sometimes does not run because it is presented the error: You cannot divide by zero. I tried to do with a case, but my code is too big and the case would leave the structure…
-
0
votes1
answer35
viewsPLSQL shows error: PLS-00103 in function when using an Exception
PLSQL is reporting error PLS-00103 when I try to compile this function. Note: If I try to run only with the first option of this case "P_TIP = 1" it runs normally. If I try to add the case "P_TIP =…
-
0
votes2
answers47
viewsSelect separate rows in SQL by adding deletion with different keys
I have two tables, one contains the chave primária, and the other takes this key in the column post_id. In the second column, she can repeat several times with the same post_id. I need to take the…
-
0
votes1
answer41
viewsWhy fractionate an Insert improves its performance?
Supposing I have a table order_items that records the items of an order, and in this example, the user would be making 1 order from 10,000 computers. At the time of registering the order items in…
-
0
votes2
answers54
viewshow to update id
someone can help me update the ID in this code? public function Editar_Cliente(){ $dados = $this->DadosClientes; $id = $dados['id']; $nome = $dados['nome']; $cpf = $dados['cpf']; $email =…
-
0
votes0
answers25
viewsHow to fill multiple text fields automatically when the main input text receives a value and loses focus?
I have a comic with the tables books and loans. On the table loans, Among other columns, I have one to put the title of the book and the code of this book. The idea is that, by inserting the code of…
-
0
votes0
answers42
viewsRepeat lines in Array: is it possible with UNNEST? or is there any other way? - Bigquery
I made this query in SQL in Bigquery (Google): SELECT FORMAT_DATE("%E4Y-%m", date) AS Mes, cliente, ARRAY_AGG( DISTINCT date ORDER BY date DESC LIMIT 2) AS date FROM…
-
0
votes1
answer49
viewsError when reading some words using percentage wildcard character (%)
Hello. I’m making some queries to the database that uses the PDO. When I make the appointment without the % at the beginning of the condition, the results return correctly. Ex.: $localizacoes =…
-
0
votes0
answers45
viewsDatabase, SQL database
I am doing a job for the college whose goal is to create a table using Oracle Live SQL So far mine’s been like this: create table ALUNO ( rgm number(8), nome varchar2(50), nome_pai varchar2(50),…
-
0
votes1
answer23
viewsINSERT using SEQUENCE . NEXTVAL with another SELECT
I can insert with this query in ORACLE INSERT INTO CONF_CODE (ID, OPTION_NAME, ISCHECKED) VALUES (SEQ_CONF_CODE.NEXTVAL, 'Producao', 0); But I need to fill this table CONF_CODE with a SELECT from…
-
0
votes1
answer51
viewsLEFT JOIN with more than one condition in ON - SQL Server
Hi, guys, all right? I’m putting together a query, and I need to do a Join. In this case, the AIV table records have a start date and may or may not have an end date. I want them to cross as…
-
0
votes1
answer34
viewsHow to merge SQL when the key variable repeats in one of the tables?
I have a dataset with two tables. In the first, I have information of workers and in the second of firms. Each of the workers has a id of the firm you belong to. I would like to create a new table…
-
0
votes1
answer96
viewsWhat is the best way to store Civil Status data in the database?
Hello, I have a question: I need to create a <select></select> in HTML for the user to select their marital status. So, I’m using PHP to save the data to an SQL database. My question is…
-
0
votes0
answers29
viewsI wanted to know the difference between the presence and absence of the first condition of the code below
I have a code that I picked up somewhere, some time ago, that I use to make connections with my database and it always worked well. I tried, then, to remove a piece of code that I didn’t understand…
-
0
votes0
answers24
viewsHow can I prevent error #1415 VB.NET Mysql?
I am doing a school work of a library management, whose database is in Mysql and the DBMS I am creating is done in VB.NET, and recently I started using Foreign Keys to create relationships between…
-
0
votes1
answer29
viewsHow to create an id variable from a query result?
I’m doing a query of a table that doesn’t have a variable id, but I’d like to assign a id to my result. The following example: Sample basis: CREATE DATABASE breaking; use breaking; CREATE TABLE…
-
0
votes1
answer46
viewsSQL Server - insert data after comparison of 2 tables
I have 2 tables where I want to compare the price of products: TABLE: PRODUCT produto preco A 4.5 B 6 C 10 TABLE: RANGE PRICE produto valor minimo valor maximo A 3.2 6.7 B 2.1 4.5 C null null I…
-
0
votes1
answer45
viewslimit an SQL table to a single record and not let the c# application insert more records into that table
Good Afternoon I’m new to this c# and SQL but I made an application in c# and I have a Company table that I want to limit to a single record ( a single company) and I want the user to change or…
-
0
votes1
answer24
viewsSelect case with subselect and Join
I need to make a select case with a subselect, is it possible? If yes please let me know where I am going wrong, else what I can do in this case: SELECT m.arquivoordemmov, m.contadoragentemov,…
-
0
votes1
answer45
viewsSQL Server select in a table returned by INFORMATION_ESCHEMA
Hello, I need to check all tables that contain the same column and make a logic to change all values of all these columns. I’m trying to get the name of the tables as follows: DECLARE @TABELA…
-
0
votes1
answer30
viewsReturn field different from the one inserted in the GROUP BY clause
I have the following table: | id | payment_id | user_id | device | ------------------------------------ 1 | 2 | 1 | active | ------------------------------------ 2 | 4 | 5 | not_active…
-
0
votes1
answer100
viewsHow to take the last sale of each customer
I have a client table: ---------------------------------------------------- codigocliente || razao || cidade || estado ---------------------------------------------------- 0001 || Sup. Mercado ||…
-
0
votes1
answer63
viewsIntermediate table mapping with JPA attributes
Hello, I’m trying to create a relationship where there is an intermediary table that has fields other than foreign keys. My classes are like this: @Entity public class Pedido { @Id…
-
0
votes0
answers43
viewsHow to pass String filter in a change from Mysqli to PDO in PHP?
// Mysqli $vf = mysql_query('SELECT id, cnpj, id_erp, fantasia, razao FROM usuarios WHERE nivel="3" AND ( nome LIKE "%' . limpa($_POST['termo']) . '%" OR email LIKE "%' . limpa($_POST['termo']) .…
-
0
votes2
answers35
viewsSQL SERVER - Changing different records in a field based on another field
Hello, I am trying to change a column in SQL SERVER (Query) based on another column. I have divergent social reason records for the same CNPJ, so I wish that for the same CNPJ only a social reason…
-
0
votes0
answers37
viewsError while trying to create index
I’m trying to create an index by command: declare cont integer; tabela varchar2(100) := 'DECLARACAO_IMPORTACAO'; coluna varchar2(100) := 'DESPACHANTE_FK'; indice varchar2(100) :=…
-
0
votes1
answer53
viewsTurn rows into columns in SELECT Oracle
Below is a select for data query in a table: SELECT 'OS:'||AT.CD_NUMERO_OS ||' ITEM:'|| AT.ITEM ||' ETAPA DA ATVD:'||AT.CD_ETAPA_ATIVID||' ATVD:'|| AT.CD_ATIVIDADE AS "DADOS DA OS", AT.DT_INICIO AS…
-
0
votes1
answer41
viewsSum of Count’s from different columns
Good morning, I have a school activity in which I aim to develop the consultations sql’s for each question. The activity has 1000 megasena results, containing the columns sorteio, data_sorteio,…
-
0
votes2
answers108
viewsSQL query to bring the last occurrence
I have a query that performs data filtering through codes, adding the existing values, only I need to bring in the "Marked" column, only the last occurrence of a phone number, Ex: I cannot change…
-
0
votes1
answer55
viewshow do Insert a foreign key that is inside a foreign key?
I intend to do Insert in the salary column and table function_name function which is foreign key in department table and this table is foreign key in official table... But the two columns salary and…
sqlasked 3 years, 7 months ago Mário Onofre Lemos 3 -
0
votes1
answer46
viewsSQL : Insert if Not Exist
Doubt: I made a form in C# connecting to the bank I wanted to know how I can include in this query the if not exits @param1 In order to avoid duplication. Link to the Reference Code: Mysql: Insert…
-
0
votes1
answer63
viewsSelect the last months, also showing the months without records
Hello. I am doing a SELECT to return the last 06 months, showing the count of records (in the example: sales), grouping by year-month. My query currently looks like this: **Schema (MySQL v5.7)**…
-
0
votes2
answers90
viewsSQL - Integer and Decimal Number Conversion
I have a field qtfornecedor of the kind Numeric(10, 3). When its stored value is 10, he returns me in consultation as '10,000'. I tried to manipulate the value with a IIF, works for when the stored…
-
0
votes2
answers33
viewsHow to search multiple columns together with max() SQL (Mysql)
The problem is this, I have the tables protocolo and historico; second stores several records linked to a record of the protocol table. I wanted to fetch the last record of each historical for…
-
0
votes0
answers14
viewsError: java.sql.Sqlsyntaxerrorexception: ORA-00979: not a GROUP BY Expression Please correct SELECT statement
I am having this error after the query. $A$ is the table nickname! I need to know how many records have duplicate number, but my query is wrong and I am unable to find the error! SELECT…
-
0
votes1
answer52
viewsTrigger Insert in the same table
Hello, I have a table where I keep records of movements, it is inserted a record where it is possible to inform a payment installment, for example, a purchase made in 12 times whose current…
-
0
votes0
answers32
viewsQuery error in SQL
I am trying to make a bank consultation for access release. When I make the following query: <?php if(isset($_POST['Login'])){ $user = $_POST['user']; $password = $_POST['pass']; $sql =…
-
0
votes1
answer56
viewsSubstring to format date within MAX and MIN
Greetings, I have this query and need to return the maximum and minimum value of a column of a table. These values are date and are written in YYYYMMDD format, I would like to display them in…
-
0
votes2
answers44
viewsRun method in Form1 for form2 change
I’m developing an inventory manager, and the data is being stored in a database. The problem I’m facing is this: when I add a new product for example, I created a "Update list" button (I left it in…
-
0
votes1
answer30
viewsINNER JOIN with 3 sql tables
I have 3 tables in the database: tbl_cupom_generated: id_cupom | nome ------ ----- 40 João 60 Maria tbl_coupon: id | desconto | id_estabelecimento ---- -------- ------- 40 50% de desconto 1 60 20%…
-
0
votes1
answer18
viewsSQL: How to copy the value of a meta_key into an array in another meta_key?
Asking here because it seems more a matter of SQL than Wordpress. I have a Wordpress installation that uses custom fields from both the ACF plugin and the template. There are over a thousand posts…
-
0
votes0
answers30
viewsAdd, update, or delete data from a column by adding, updating, or even deleting data from another column:
Hello! I am starting in Java programming and also in Oracle SQL and I have a problem: I need a particular record of a column of a table to be updated, added or removed from a column of another…
-
0
votes1
answer32
viewsINNER JOIN with SOMA - SQL
Good morning! I have two tables in access that present me CPF and value, but I am not able to join the two tables adding the amount. As I do not understand access, I am trying to make the query via…
-
0
votes0
answers19
viewsHow to make an Insert with select using bdlink
I need to do an Insert along with select looking for data from another database, for this I’m using dblink, but I’m not getting, I use pgadmin4 declare insertCad RECORD; begin for insertCad in…
-
0
votes1
answer24
viewsError in the subselect of an sql script to generate update script bringing more than one line and giving errors
I have two tables, a partner of which some fields of cnpj_cpf are wrong and another that I went up with the corrected data, totaling I have approximately 1 million lines to solve, so I generated a…