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
answer1338
viewsProblem with BETWEEN dates
I need a light for a question, I have a data filtering system (search) where I have to search for two Initial and Final dates. Since I have these two columns in the database, then when I run the…
-
1
votes1
answer62
viewsHow to avoid performance problems with tables that contain a lot of data?
I am developing a payroll system, in which there is a "problem' in one of its tables. Because, to control the discounts on the holerite of each employee, I thought to create a table with the name:…
-
1
votes2
answers1487
viewsSave Image in Database with C#
Hello! I saw the example Upload image to picturebox and write to database but I didn’t get that part: FileStream Stream = new FileStream(imgLocation, FileMode.Open, FileAccess.Read); What would this…
-
1
votes1
answer667
viewsAssign a cursor value to a table column
I have a cursor. I need an Insert to insert the value of each cursor position into a table. How do I do this? I need to enter the cursor value exame_cur. My code below: set nocount on declare…
-
1
votes0
answers31
viewsHandling Entity Framework Data Using C#
I have a database connection using the Entity Framework. The code is as follows: public IQueryable Empresas() { int idUser = Int32.Parse(self.IdUser()); var res = from s in db.EmpresaUsuario join c…
-
1
votes2
answers1252
viewsHow to remove duplicate query values in two tables?
I’m doing a query in two tables (students and users) and picking up the id, name and email values. Right after I do a Union between them. However, I wish there were no lines with duplicate values…
-
1
votes1
answer751
viewsDivision error by zero - Query SQL
I have the following query below, however, when I run it, the following message occurs: erro de divisão por zero. I tried to use the function nullif, but without success. How to solve? SELECT…
-
1
votes0
answers110
viewsJoin two df using the sqldf function
I’m trying to put two tables together using the same species id, but I’m not getting it. Below follow the steps: Importing the fixed file to TNRS for R hp<-fread('tnrs_final.txt', header=T) Now…
-
1
votes1
answer83
viewsProcessing cost between code and database
Among the many forms of development, there was a doubt about what will consume the most of my processing between the same operation in different ways... If I have a function that can be done…
-
1
votes1
answer131
viewsDelphi Add line in SQL error LIST OF BOUNDS (3)
I have a problem adding a line to my SQL LIST OF BOUNDS (3) Delphi : clausulaIn := 'AND A.NNUMEMAPAF IN (0'; while not Q_Mapas.Eof do begin clausulaIn := clausulaIn + ',' +…
-
1
votes1
answer512
viewsSub-Select with MAX / SUM / INNER JOIN?
I need to make a SUM within a MAX to return higher product billing within a summary. I got by doing this: SELECT MAX(Faturamento) MAX_Faturamento FROM (SELECT SUM(P.preco * I.qtde) Faturamento FROM…
-
1
votes1
answer319
viewsError compiling function in oracle
When trying to compile the following Function: CREATE OR REPLACE FUNCTION f_id_fornecedor(Nomefornecedor in varchar(50)) RETURN integer IS codigoforncedor integer; BEGIN SELECT codfornecedor INTO…
-
1
votes1
answer37
viewsPrioritize keywords found in the title in the sql search
Hello, I have a table 'videos' with 3 fields 'name', 'Description' and 'categories'. When doing a search I want to appear at the top the videos that in the 'name' have more of these keywords, for…
-
1
votes0
answers133
viewsMonitor Mysql server activities
I have a network-hosted system (php and mysql) here in the company, installed on several stations. I wonder if there is any command or tool for monitoring requests (queryes) for made to the MYSQL…
-
1
votes0
answers26
viewsHow does the automatic indexing of a blog work?
I’m creating a news site, and I see sites like G1 and Tecmundo using an automatic indexing for their news, how does it work? Well, I’ll explain it better: I have a file that reads the news through a…
-
1
votes1
answer530
viewsStandard structure of a SQL Server database
I have a model structure, I wonder if it is suitable to a good standard. USE [teste] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author:…
-
1
votes1
answer69
viewsSubtract the current value from the previous one
I’m trying to make a supply system, I need it to take the last km registered in the bank of a specific vehicle and be subtracted by the new that will be inserted I’m trying to do so, but it shows no…
-
1
votes1
answer343
viewsHow to make a Radius calculation in SQL, using Mysql, with two conditions?
Hello, I already do a radius calculation in SQL, using Mysql and PHP, which takes the location of the device (latitude and longitude) and filters the radius according to the location of the device.…
-
1
votes1
answer59
viewsError executing Oracle command
Everybody, good afternoon, everybody, I’m having trouble calling a function in Oracle... This is the function: function mataSessao(){ $connect = oci_connect('xxxx','xxxx','xxxxx','xxxxx'); $IDSESSAO…
-
1
votes0
answers282
views'SET ANSI_WARNINGS ON' Orange 5.4
I am using Laravel 5.4 with 2 connections, one of them is just to access some Views of a Sql Server database, and one of them makes a LINKED SERVER which forces me to set some settings before making…
-
1
votes1
answer327
viewsHow many percent N item represents in the overall total - Query
Good morning, I’m creating an ABC curve report but I’m beginner and I’m still having some difficulties. I have a table called ITEMS. With fields: COD_ITEM, Quantityevenda, Valorunitario, Subtotal,…
-
1
votes1
answer770
viewsAutomatically delete a record from a table after a time interval
How do I after a time interval the record is automatically deleted, as in a shopping cart, for example?
-
1
votes1
answer113
viewsUpdate Postgresql
I have a question, a customer reported that there was an error in the registration of his products, and the employees registered the cost price as the price practiced and vice versa. Could I run an…
-
1
votes1
answer4491
viewsSafe update error using stored Procedure in MYSQL
I am having trouble updating my stock table using a stored Procedure in MYSQL. Follows the code: CREATE DEFINER=`root`@`localhost` PROCEDURE `atualiza_estoque`(id_produto int) BEGIN update estoque e…
-
1
votes1
answer61
viewsDoubt - SQL Server 2012 Query
People, in the query below want to put a condition within the Where that bring only the tasks that are due two months after the opening date. For example. The task 11111 was opened on 01-11-2017 and…
-
1
votes4
answers179
viewsCreate method that avoids code repetition in ASP.NET with SQL
I am building an ASP.NET site, using C#. I want to 'link' the site information (text and images) in an SQL Server database. This part of connection I’ve managed to do successfully. However, I have…
-
1
votes2
answers162
viewsPrevious dates
I am making report in which I need to always get the date of customer registration in a previous month. Example: I am in the month of December 2017, I want to pick up customers who were registered…
-
1
votes2
answers67
viewsConvert Data Sqlserver
I would like to convert02/01/2018 for 2018-01-02 00:00:00.000, what I found on the internet so far was: select CONVERT (datetime, '02/01/2018', 120) Who returns to me2018-02-01 00:00:00.000, a…
-
1
votes1
answer321
viewsproblems to create multiple tables in Oracle
I am beginner in the use of Oracle, wore the firebird before. I’d like to know, why I can’t create multiple tables at once in the SQLdeveloper. It creates only the first table (Country). I try to…
-
1
votes3
answers2770
viewsSelect from the line with the highest ID
I have the val_products table, where you have id_product and product value, I need to select * only on the line whose ID is the largest, for example, I have two products with ID’s 1 and 2, but I…
-
1
votes2
answers4225
viewsConvert Varchar to Time in SQL with data longer than 24 hours
I am developing an SQL query and in case I need to convert a field of hours that is in varchar for time to then make a media of this field (I will use Datediff together). The problem is that CONVERT…
-
1
votes2
answers167
viewsError with SQL and Mariadb (Current position is before the first Row)
I have a problem in my database and I have no idea what it is. public String getBlockPermission(String blockstring){ String permission = ""; try{ ResultSet res =…
-
1
votes1
answer5710
viewsInvalid SQL identifier - Oracle
CREATE TABLE IndustrialUnit ( UnitId NUMBER (7,2) PRIMARY KEY, Location_place VARCHAR(50), Country VARCHAR (50), FOREIGN KEY (ProdId) REFERENCES Production(ProdId) ); When I try to define the…
sqlasked 6 years, 10 months ago Diana Madeira 485 -
1
votes1
answer76
viewsQuery Rows having Maximum value in a column
I have a problem with a query on a bench Oracle in a table with 3 columns: Id_loja | Canal | Valor_venda There is the possibility of having more than one sale per store and I want to know which…
-
1
votes1
answer241
viewsGroup data from a Query?
I do a GROUP BY in a query result and the result comes this way: I wonder if it is possible to bring together in this way? I wonder if this grouping is best done in PHP or Query and how it can be…
-
1
votes2
answers1117
viewsChange oracle characterset 11g
When performing a dump file import, oracle is returning me the following messages: IMP-00019: rejected line due to ORACLE 12899 error IMP-00003: Oracle error: 12899 found ORA-12899: very large value…
-
1
votes1
answer181
viewsMYSQL Sub-Query (SELECT MIN)
I have this code, but what I want is the SELECT MIN "n_rowers" and only the min number. I wanted the club with fewer rowers. Help? :) SELECT (clube.nome) AS clube, COUNT(remadores.cod_remador) AS…
sqlasked 6 years, 10 months ago Diogo Neves 19 -
1
votes0
answers37
viewsMonitoring of SQL script
Someone can help me, In my company I have a script that checks how many emails have been processed and sent by the server, but sometimes the program that makes the submissions crashes and I only…
-
1
votes1
answer251
viewsError in update sql: Subquery returned more than 1 value. This is not permitted when the subquery Follows
I am performing a query to change the net cost of a product according to a brand, however, I get the following error message: Subquery returned more than 1 value. This is not permitted when the…
-
1
votes1
answer149
viewsTesting UPDATE in Postgres
The idea is to do a search with the BEFORE result, run UPDATE with the appropriate changes and run a new search with DEPOIS, then undo all the changes, a test for UPDATE. SELECT id_evento,…
-
1
votes1
answer1091
viewsPerforming UPDATE on ORACLE using FROM
How to do UPDATE in Oracle records without using a clause IN to change data in bulk? Thus: UPDATE TABELA1 SET DADO = DADO FROM TABELA2 WHERE TABELA1.CODIGO = TABELA2.CODIGO; Currently he me force to…
-
1
votes1
answer65
viewsDate field display
I have a date in the format americado yyyy-mm-dd and I would like to put it in the Brazilian format dd-mm-yyyy but I don’t want to do it as conversion to_char. I need you to continue with the date…
-
1
votes0
answers37
viewsSql Pagination in the past
I’m trying to implement the sql pagination in my Procedure, I have already taken several examples but I did not get the desired result. I have a trial that makes Lead queries at my base. I would…
-
1
votes1
answer2522
viewsCalculate average call time
Guys, I need to take the average attendance time and I have the following data: 00:12:35 00:05:10 00:01:42 00:08:12 00:01:01 {...} The question is, how can I do it? I searched for a way to do it…
-
1
votes1
answer1067
viewsDifference between hours and minutes days in Sql Server?
I got two columns like datetime. I have tried in many ways to catch the difference between them, but the number of days is always incorrect. Example: Data1: 2018-01-17 17:00:00 Data2: 2018-01-18…
-
1
votes1
answer345
viewsCompare End Date of the first record with Start Date of the second
Hello. I’m having trouble drafting a SELECT that checks whether the End Date of the first query record is greater than the start date of the second. The database in question is of notes and for some…
-
1
votes1
answer1810
viewsHow to convert dates into varchar to date in SQL `Firebird`?
How to convert dates into sweep for date? I’m having difficulties in performing searches between dates, due to this discrepancy in the database where I perform the query. When I enter my line of…
-
1
votes4
answers1103
viewsSELECT with two results
Table: PEOPLE id - nome 1 - BEATRIZ 2 - MARIA 3 - CARLOS 4 - MARIA 5 - JÉSSICA 6 - HENRIQUE How do I make a SELECT that gives me as a result a list of the names ordered by ID descendente, however, a…
-
1
votes1
answer378
viewsError creating file in oracle
When declaring the name of a trial in sqldevelope get that message Erro: ORA-00972: identifier is too long Example of nomenclature: PRC_IMVW_TISS_VERIFICA_ELEGIBILIDADE CREATE OR REPLACE PROCEDURE…
-
1
votes0
answers57
viewsNormalize table for 2FN
I have a super badly made table in my hands and I need to normalize this up to 2FN. Can someone give me some tips? I am not being able to apply the theory in this table. Here is a sample of it: (the…