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
answer48
viewsError to insert data into a table
Please, I am trying to make an Insert in a temporary table but this giving the error reported below: code used for insertion insert into #basehot(email) select distinct a.email from #email a right…
sqlasked 5 years ago EltonSilva 11 -
1
votes0
answers55
viewsSubtract sum of two columns
I have a table with this structure: ...| tipo | quantidade E 20 S 15 E 500 the column tipo can be "And", incoming, and "S" exit. and the quantidade is a number. How can I make a select add all type…
-
1
votes0
answers81
viewsCRUD Android doubts
Good afternoon I’m with 3 doubts regarding a crud I made in my app. 1 I did a field search and it seems that does not pick up any phone of the line J7 and I was wondering if someone can tell me why…
-
1
votes0
answers1256
viewsSQL Error [1064] [42000]: You have an error in your SQL syntax
When I add a new row to the table I can delete using the command: DELETE FROM ebdb.tb_categoria as tc WHERE id = 790; However, the lines that already exist cannot delete and returns the error: check…
-
1
votes1
answer28
viewsInclusion of First Record using a select SUM
In certain routine I have a Trigger that runs a code similar to the one below. I’m having trouble in the first record, as in the first record does not have any code, the sum of + 1 is not being…
-
1
votes0
answers44
viewsSet value of another table in the column of the current table (search value by ID)
I’ll get right to the point. My sql table looks like this: id, venda_id, produto_id, qtd_saida, preco_produto I’d like to fill in the column preco_produto automatically when the product be saved.…
-
1
votes1
answer69
viewsGENERATE A SELECT WITHIN A PROCEDURE
Good evening, everyone, I’m trying to make a select within an ORACLE database, only I’m not getting it. Below is an example of code I’m trying to generate. CREATE OR REPLACE PROCEDURE TRAZNOMES IS…
-
1
votes1
answer286
viewsJAVA - Database connection - Sqlexception error: Parameter index out of range
Hello! I’m new to Java, and I came across this problem: Netbeans accuses that I am not respecting the SQL parameter limits, but are correct. Part of the error in question: Testando conexão com banco…
-
1
votes1
answer207
viewsAdd fields in a select
As that puts the idautor and idobra in this my SELECT: CREATE TABLE Obra_Assunto ( idassunto INTEGER NOT NULL, idobra INTEGER NOT NULL, PRIMARY KEY (idassunto, idobra), FOREIGN KEY…
-
1
votes1
answer91
viewsSum return of select
I have the following query: SELECT (case when day(sysdate()) < 10 and meses.mes = month(sysdate()) then 0 else CAST(SUM(CASE WHEN s2.name LIKE '%Servidores' THEN ( coalesce(ta.time_unit,0) *…
-
1
votes2
answers1305
viewsHow to store product lists of an order in a database table?
I have the following database modeling so far: I’m wondering how best to store the products in the order table. One string with Id of all products for each order in the table? I think very bad. What…
-
1
votes2
answers301
viewsBring the records from one table according to the Where from another
I am new in the database area and I came across a situation that I do not know how to solve. Even though it seems (at least, rs) simple. Exists the table called dbo.FISICA and another call…
-
1
votes1
answer578
viewsORDER BY or LIMIT. What is processed first in SQL Select?
Friends, what is first processed in SQL Select? "Order by" or "Limit"? For example, if I have a table with cities of several states. Then I search the cities with more than 100 thousand inhabitants…
-
1
votes1
answer37
viewsDoubt Select in Mysql
I have two city tables and people City has the columns Id/idPrefeito/idVice/nome And people Id/nome... Idmayor and Vice are Foreign Key’s people.id How do I carry in the same select the name of the…
-
1
votes1
answer624
viewsSum values in a Select (postgres)
I have a small problem, I need to fill a gridView in C#, but my query is not adding up some values and this is causing the company code to be repeated and with the value "separate". The value I need…
-
1
votes1
answer675
viewsWhat is the difference between JOIN and UNION in SQL?
What’s the difference between JOIN and UNION in SQL? I thought a query made with either of the two would result in the same table, but I’m taking a course at Datacamp where the teacher says these…
-
1
votes3
answers249
viewsDOUBT IN SQL -TURN ROWS INTO COLUMNS
I got this one query, it brings to the same product 3 rows of result, wanted these results to be returned in columns, how to do? SELECT CODPROD, EMB FROM TABELA WHERE PRODUTO = 2 this research…
-
1
votes1
answer641
views -
1
votes1
answer1068
viewsInclude column in a select
In my work, I always extract from sql, tables, in one of these tables the extracted information is contracts, date, dialing Qtde, service Qtde, Alo Qtde, and so on. I use Rstudio, with a connection…
-
1
votes1
answer34
viewsQuery the database using ORDER BY kills my search
My code displays a list of people and a search field at the top. everything works normal, including the search. But I need people to show up at random. The problem is that when I use ORDER BY Rand()…
-
1
votes1
answer53
viewsRecover orders customer 1. DUPLICATION ERROR
My code: SELECT Pedido.NumPedido , Pedido.CdCliente , Cliente.Nome , Produto.CdProduto , Produto.Descricao , PedidoItem.Quantidade , PedidoItem.ValorUnitario , PedidoItem.ValorTotalItem FROM Cliente…
-
1
votes0
answers26
viewsR and SQL - How to join a data.frame in R with a table in SQL?
I have a table in Postgresql that contains the column "cnae". I also have a data.frame in the R with columns "cnae" and "Description". I need to move the "Description" column up to the table in…
-
1
votes1
answer202
viewsHow to update column for each SELECT in a given table?
I tried to create a trigger for a table using for it to be activated after each select, but researching a little I discovered that it is not possible to create triggers for selections, only for…
-
1
votes1
answer62
viewsSum result of 2 fields
I could use a little help with a consult. I have a sales chart where has the field vltotal and vldevolucao, the total of these fields already managed, but I’m not getting the result of the sum of…
-
1
votes1
answer521
viewsSQL - Function to calculate working hours considering business hours, working days and holidays
I need a function to calculate working hours considering business hours, working day and holidays, I have searched in several websites and can not find any function that contain all these…
-
1
votes1
answer87
viewsWhat is the best way to store data locally?
I need to develop a web system to run without a server, the system in question will only save client data and schedules. I would not like to use a database server, because it becomes annoying that…
-
1
votes2
answers56
viewsRails - query for non-connecting records
I have a Rails application and am creating a notification system, the problem is that I do not know how to query by notifications not viewed by a user in a practical way. The scheme of the…
-
1
votes1
answer333
viewsHow to duplicate a key’s value in SQL?
I need the keys Process and Numero_revisao, can receive values that already exist in the table. for example: Id = 1, Numero_Processo = 1, Numero_Revisao = 1 Id = 2, Numero_Processo = 1,…
-
1
votes3
answers464
viewsdrop table with temporary table giving error
qryCIDtemp.SQL.Text := 'drop table if exists #tempCID'; //apaga a tabelas temporária Delphi returns me the following message at runtime: Invalid use of keyword Token: if Line Number: 1. If anyone…
-
1
votes0
answers20
viewsLarge Object postgresql
Someone knows a replacement function or script for postgres lo_export, my problem is that I am migrating the databases to a server separate from the application and would not like to use folder…
-
1
votes0
answers18
viewsPerformance between Mysql Update types
Good evening, I need to update a table 'a' in the rows where there is no occurrence in table 'b', where table b has about 7 million records. I imagined two solutions but I can not say which would be…
-
1
votes1
answer247
viewsHow to insert this text in Postgresql?
I am using a Delphi query and need to insert the text below in a text field {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\froman\fcharset0 Times New…
-
1
votes1
answer104
viewsAVG Oracle returning very broken value
Speak my darlings, I’m making an oracle average with the AVG function... select avg (checkd) from table Only it sometimes returns a very broken number, for example…
-
1
votes1
answer96
viewsSubtract values using sqlite in Python
I want to do the following: Create a function with a quantity parameter, thus causing the value of the parameter to subtract with a value from a table field: Example: sell(5), this 5 will subtract…
-
1
votes1
answer62
viewsReturn of Maximum value
Good morning, I’m conducting a course and I’m stuck on an exercise. In the exercise I have to return the maximum popularity value of each musical genre by country, so far all well, I managed to…
-
1
votes1
answer51
viewsTrigger gives error with date
I made a Trigger to count the working days. It accepts the dates of the month 06 very well, but other dates gives the following error: INSERT INTO `teste` VALUES ("2018-05-01") #1292 - Incorrect…
-
1
votes3
answers113
viewsSQL Server - Query logic
Note the result below: This is the result of the following query: select *, isnull(h,isnull(f,isnull(d,isnull(b,isnull(a,0))))) as y1,…
-
1
votes1
answer481
viewsSyntax error in with SQL Server
Tenh the following error in sql server: Incorrect syntax near the keyword 'with'. If this statement is a common table Expression, an xmlnamespaces clause or a change tracking context clause, the…
-
1
votes1
answer880
viewsMultiple rows in a Sql Server column
I have a problem where I need to join the return of a query made in two tables in a single row. I thought I’d use PIVOT but I couldn’t because of INNER JOIN. The consultation is like this: SET…
-
1
votes1
answer34
viewsEmail automatico no sql server 2012
I have a problem at the time of putting the query in the body of the email, this giving me error asking for EXISTS in the query how I can solve it. Follows my code. DECLARE @p_body as nvarchar(max),…
sqlasked 6 years, 4 months ago Junior Guerreiro 617 -
1
votes1
answer26
viewsSearch data via SQL using Laravel
I need to select to return all users who have the initials of a name. Example: I type in my search input field: "paulo" returns to me all users who have this word. I did some research and used it:…
-
1
votes1
answer314
viewsSQL - How to override ambiguous external junction?
I’m trying to normalize a database for addresses and zip codes. However, there is a situation in which the Post Office assigns, for the same street, a ZIP code to the side with even numbers and the…
-
1
votes2
answers102
viewsSelect with fields without values
I’m making a SELECT where I join two tables: a stock balance table and another order table. I’m making a comparison between product balance in stock and balance on purchase orders, only the way I’m…
sqlasked 6 years, 4 months ago Junior Guerreiro 617 -
1
votes1
answer243
viewsForeign key with 3 primary keys
Hi. I have this table with 3 primary keys and I need to reference it in another table. It’s like? I was just going to put an int-type id in the monthly table to be the only primary key. But each…
-
1
votes1
answer1123
viewsDatabase query error - invalid number
Good afternoon. I’m having trouble with a database query. When performing it, returns this error: ORA-01722: número inválido 01722. 00000 - "invalid number" *Cause: The specified number was invalid.…
-
1
votes2
answers828
viewsDoubt when creating table with dates in postgresql
I have the following table structure: I would need to create a 3° table that would look like this: I have the smallest and longest date in one table and in another table I have changes made, I would…
-
1
votes1
answer497
viewsExcel and SQL - Connection between Excel file
I have the code on (end) that I picked up on the internet. This line of code gives error in WHERE, because it is a text: strSQL = " SELECT [VENDAS$].[Data], [VENDAS$].[Vendedor], [VENDAS$].[Total]"…
-
1
votes1
answer75
viewsTake value from right set with 'ambiguous' fields
I am making the following query to my database: $escalacoes = 'SELECT * FROM escalacoes AS e JOIN jogador_rodada AS jr ON e.id_jogador = jr.id_jogador WHERE e.rodada = ('.$rodada_atual.' - 0) AND…
-
1
votes0
answers1274
viewsConnecting C# to SQL Server
I am trying to connect a program to the database hosted on SQL Server, but am having problems.. When the program runs, the login screen is the first to appear, and from it I need to open the second…
-
1
votes1
answer65
viewsHow to perform 1 position offset SQL query?
I’m trying to perform a query where in one of the columns (COTA_DIA_ANTERIOR) return me the value of the previous day. But it is bringing the value of the day. SELECT ET.DT_REFERENCIA ,ET.VL_PU…