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
votes2
answers247
viewsQuery in the same table
I have a movement table that has worker’s record and related events, wanted a query that returns only the records that have exactly the events E1,E2 and E3, in the case of the above example the…
-
1
votes7
answers412
viewsMount an sql query filtering data
I am trying to assemble a report, where I need to list deleted documents, I have the following sql statement: SELECT id,nf,status,data FROM documentos For example I have the following results: When…
sqlasked 7 years, 2 months ago Smoke Rohden 793 -
1
votes3
answers229
viewsDisplay the result of a COUNT in the Database
The PHP code looks like this: $con = new PDO(SERVIDOR, USUARIO, SENHA); $sql = $con->prepare("SELECT COUNT(id) FROM quiz;"); $sql->execute(); $n = $sql->fetchObject(); And the HTML code…
-
1
votes1
answer83
viewsQuery in two tables
Well, how do I query two sql tables? For example, I have a table Enterprise with the fields id,social reason, and cnpj. I also have another table, Subsidiary with the fields id,addressee,loan. I…
-
1
votes1
answer396
viewsEntity Framework vs SQL Injection (security?)
Hello! I’m new to development so excuse me if the question is silly. If it’s thanks link’s with references so I can better inform myself. As much as I understand the concept and the use of SQL…
-
1
votes0
answers47
viewsHow to send combobox data to a DBMS sql server?
I have an application where one of the formularies contains a comboBox with data entered from the property Item (Collection). How to send data that is in this comboBox to a sql server database ?…
-
1
votes1
answer3357
viewsWhat is the number of decimal places of type NUMBER(12,2)?
How to know the number of decimals for type NUMBER(12, 2) in an Oracle database ? V_FATURA NUMBER(12, 2)
-
1
votes2
answers1009
viewsRepeat previous rows when there is no record in SQL SERVER data
Friends, good afternoon! I came across a problem at work today, and I still haven’t found a solution to it. As I do not have much experience in the database area I am having difficulty to solve this…
-
1
votes1
answer207
viewsQuery to count table dependencies
Let’s assume I have a database with only 50 tables. In the structure, I have several connections, several foreign keys. There is a way, so to make a query that brings the amount of dependencies of…
-
1
votes1
answer38
viewsDelete Rows from a table except a MYSQL amount
I have in a table the columns: codigo, cliente, token_md, val, cartcodigo, clientenome, clientesobrenome, clientecpf, clientenascimento I need to delete exactly 46,550 rows from this table, no order…
-
1
votes1
answer31
viewsAdd year to my sql search clause
I set up a trial that does a search for the amount of hours pointed out per month of each employee of the company. The trial works well, but I noticed that she ends up looking for years past and I…
-
1
votes1
answer255
viewsSQL command does not work with select
Follow my complete code: <? include("conectar.php"); $query = "select * from pagseguro ORDER BY Referencia DESC"; $result = mysqli_query($db, $query) or die(); if($_REQUEST['alterarStatus']){…
-
1
votes1
answer1282
viewsSee the best-selling product
I’m having trouble joining two tables and using some aggregation function, I’ve tried it like this: SELECT nome FROM produto INNER JOIN vendaproduto SUM(quantidade) ON produto.idproduto =…
-
1
votes1
answer34
viewsReturn the value to the left
good morning. A question, how can I return the results of a column that contains only the values to the left that start with the word 'car' for example? I am using sql server. Thank you.…
-
1
votes1
answer926
viewsHow to make Inner Join in associative table?
Tables and Indexes: CREATE TABLE CLIENTE( IDCLIENTE INT PRIMARY KEY AUTO_INCREMENT, NOME VARCHAR(30) NOT NULL, SEXO ENUM('M','F') NOT NULL, ID_CARRO INT UNIQUE ); INSERT INTO CLIENTE VALUES…
-
1
votes1
answer109
viewsGet Constraint and drop name next
I have a constraint UNIQUE in the PERSON table and is from the field CPF. To get the name of this contraint I use the query: SELECT UC.CONSTRAINT_NAME FROM USER_CONSTRAINTS UC INNER JOIN…
-
1
votes1
answer3935
viewsORA-01704: too long string literal
I have a CLOB type field in the BD, but when I give an INSERT it returns me an error saying that exceeded the field size that is 4000 characters. Relatório de erros - Erro de SQL: ORA-01704: literal…
-
1
votes1
answer62
viewsSQL function with mysql
I am implementing a function for a vendor search field and my sql function is in trouble, would anyone know what problem? This was a function of when using postgree, but now I’m using mysql. package…
-
1
votes1
answer210
viewsStart and end of a month/year last in parameter (Oracle)
I need you to return the total monthly data according to the MONTH and YEAR parameter reported. I did it this way: WHERE a.dt_mesano_referencia between to_date('01/'|| :NR_MES ||'/'|| :NR_ANO ||'…
-
1
votes1
answer999
viewsLEFT OUTER JOIN
I have a table in Postgresql. I would like to count two columns where one has more record than the other. If I use LEFT OUTER JOIN I think it will work, however, I’m not succeeding with the…
-
1
votes3
answers1529
viewsEliminating duplicate values in SQL
I have a problem in a query, because there is only one field that differs from one data from another. I have tried using group by, order by, having, I searched in several forums, anyway, I tried…
-
1
votes2
answers683
viewsSum (SUM) of an irregularly formatted column
In my Mysql table I have a column called "weight". This column has the following values: 19.325 14.369 15.325 15.369 17.698 19.258 18.098 I simply need to accomplish the sum, but when I perform…
-
1
votes0
answers42
viewsDifferent results 'Count(*) from V$ASM_DISK'
I have a script that connects on an Oracle basis and makes the following select: select count(*) from V$ASM_DISK; This script is in a . sql file, then I make the following call in the OS:…
-
1
votes1
answer584
viewsCreating Table/BD with Django?
I use python 3.4 and the latest version of Django, I am using the command "python Manage.py sqall" but does not recognize the sqall command. (I’m trying to create a table in Bd, and already insert…
-
1
votes1
answer149
viewsProblems updating data with empty Datetime
I need help with the following... I need to update several data at once through my application, however, one of the conditions is that the field exit in the database is empty as it will be updated.…
-
1
votes1
answer846
viewsSelect in Firebird with PHP using conditions
How do I correctly include select below in php code? I’m having a hard time doing WHERE. SELECT ESTOQUES.produto, ESTOQUES.cor, ESTOQUES.tamanho, ESTOQUES.filial, CODIGO_BARRAS.barra, ESTOQUES.saldo…
-
1
votes1
answer76
viewsTemporary table with underscore
I am trying in my service to create temporary tables as I have always learned, putting # in front of the name I want. But I don’t know what happens when I create one, it puts a huge underscore and…
-
1
votes1
answer57
viewsError in SQL QUERY
SELECT COUNT(*) AS total FROM table GROUP BY (YEAR_MONTH FROM data) ORDER BY (YEAR_MONTH FROM data) ASC _YEAR_MONTH_ and I don’t know why…
-
1
votes1
answer310
viewsExport Text field to Bytea in Postgresql
I could make an application to export the contents of a Text field to Bytea without problems, but since there are thousands of records I believe that if I do via SQL will be faster. If that is…
-
1
votes3
answers200
viewsSelect bringing maximum Columns with Writing - MYSQL
Guys, I have the following structure in a Mysql table: https://prnt.sc/k0d0ev I need to make a select that brings me as many posts as there are any records, for example, in reference 269 bring me to…
-
1
votes2
answers865
viewsSelect to know customers without service in the last 30 days plsql
I have the following columns: CODCLI, CLIENT AND DTULTCOMP I need to know which customers you haven’t bought in the last 30 days. the DTULTCOMP column is in DATE format Table: PCLIENT
-
1
votes0
answers334
viewsError 1452 mysql: foreign key error
I created two product tables to tbl_produto and the tbl_adiciona, so instead of every time I want to update the stock, I don’t have two equal data in the product table, but in an outside table.…
-
1
votes2
answers1727
viewsOracle-Variable without data
I have a problem and a doubt at the same time, I made a function to see invoiced orders and declared a function variable so: select filsaida into v_loja from mov_itped where pedido= p_pedido and…
-
1
votes1
answer68
viewsSQL Server Doubt 2012 - Query
I am having a hard time. In the consultation below, you are bringing in this way. Tarefa_Inclusao Tarefa 167909 167920 SELECT TarIDInclusao [Tarefa_Inclusao],tarid [Tarefa] FROM Tarefa WHERE TarID =…
-
1
votes1
answer2740
viewsHow to use LIKE with OR on Oracle?
I have the following table: CREATE TABLE DEPENDENTE ( IdDependente number(6), Matricula number(6), Nome char(50) NOT NULL, dtNascimento date, constraint pk_IdDependente PRIMARY KEY(IdDependente),…
-
1
votes2
answers138
viewsgroup columns in mysql
Have these Insert in the table I would like an sql me returns the total points of the type team: time - points Uruguai - 9 Russia - 6 Rabia - 3 Gito - 0…
-
1
votes2
answers1521
viewsQuery SQL - put result in a row only
SELECT pga.Titulo, e.Codigo FROM Qualidade_Diagrama_Processo_Grupo_Acao pga JOIN Qualidade_Diagrama_Acao_Entidade ae on (ae.Id_Proc_Grupo_Acao = pga.Id) JOIN Qualidade_Diagrama_Entidade e on (e.Id =…
-
1
votes1
answer162
viewsSQL doubt using subquery and IN command
I need to do the following. So-and-so has several car models. I want to list other users who also have 3 specific car models that so-and-so has. What I did: $iduser = id do fulano $mod1 = modelo de…
-
1
votes2
answers47
viewsHow to dynamically get specific day in a query
I would like to get the last day of the previous month in a dynamic way. I don’t know how to put the wo.createdtime <= Moth(current_date) something of the kind and this is in milliseconds,…
-
1
votes0
answers78
viewsPath to upload with variable
I’m looking to use a "changeable" upload path. I made a bidding system, that each new bidding, is created a folder with the name of the same where will be uploaded the files related to it using…
-
1
votes1
answer2196
viewsHow to call a "Stored Procedure" oracle c#
I have the following Procedure in my bank: I’m trying to call my store Procedure in the .net in this way: public int CountEvent(int resourceId, int eventCounterDefinitionId, DateTime startDate,…
-
1
votes1
answer97
viewsSQL Alphabetical sorting with html code
I have a table that contains the field titulo. I have a query and want to sort alphabetically by it, however, some fields are with HTML code, I will give examples: Goat Slaughter and Meat Processing…
-
1
votes1
answer680
viewsReturn Oracle PL/SQL string range
Good morning ! I need to return the value inside a string between a range of | in the select below I can get the value from the first |. The expected result is: 83,1 SELECT…
-
1
votes1
answer52
viewsHelp with logic in SELECT
I have a "matchmaking" script (like a game). He checks every 3 seconds a table, to see if there are 10 players who are not playing. Only that I also need to check if among these 10 players, one of…
-
1
votes1
answer375
viewsdate + 2 working days
I have a date (fatura.baixaboleto, "%d%m%y") and in this consultation I want to add 2 more working days, example: Day 16/07/18 + 2 working days = 18/07/18 (Monday to Wednesday) Day 19/07/18 + 2…
-
1
votes1
answer156
viewsCompare group by sql server values
Something very unusual happened in my bank. Some records were entered more than once (7 to 13) to be exact. This occurred due to software error that has already been solved. Now I need to delete…
-
1
votes0
answers15
viewsHow to reorder the result of a query if it has a specific result?
I have a query (select nome from coisas;) that returns to me for example: escova mesa cadeira garfo How do I make so that if there is a "chair" in the results, it always appears first, and the…
-
1
votes2
answers61
viewsProcedure sql server 2012 + java
I want to structure an INSERT using JAVA in the same way that INSERT is structured in VB .NET. It follows how the code is in VB . NET: Const _spName = "dbo.MEJT_SP_CAD_PRODUTOS" Public Function…
-
1
votes2
answers111
viewsWrite in search field date in dd/mm/YYYY format and search in the database in YYYY-mm-dd format
I want to type in the form the date in the format dd/mm/YYYY but search in the database in the format YYYY-mm-dd, please already tried everything, from a HELP Ai
-
1
votes2
answers332
viewsMysql - Select between 2 tables with "String" field
I would like to know how to do a Select to return the nonexistent records, comparing two tables with String field. Example: Tabelas Campo1 Campo2 Tab1 Nome Tel Tab2 Nome email The result of the…