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
votes2
answers762
viewsHow to put ISNULL in Subselect with case?
How do I return instead Null return as Não. I’m having second thoughts about using the ISNULL within the Subselect along with the case. Upshot: Projeto teste Null Projeto OK Sim. Instead of Null I…
-
0
votes1
answer293
viewsCompare values using SQL
I find myself in the following picture situation I need to compare the value of the property with the minimum and maximum filter value but due to the semicolons I get no results. How can I solve…
-
0
votes1
answer46
viewsDifference of Character and charset
I’m picking up a few things in SQL, and sometimes I come across CHARSET and CHARACTER For example: create database teste default character set utf8; And now, creating a table: create table teste (…
-
0
votes0
answers30
viewsCreate GRANT on condition
I have a DRIVER table (columns: name, cnh, address, dots_wallet) and a GRANT analyst. The analyst can only access data from drivers who have more than 0 points in the wallet. Grant select on…
-
0
votes1
answer208
viewsSelect with pyodbc
I am trying to use the string I get from an Entry and Optionmenu to perform the Sqlserver search but from the following error: TypeError: not enough arguments for format string Here is the code of…
-
0
votes2
answers104
viewsProblems Making Simple Insert in Bank - Unexpected Token
I’m having problems making entries in the database, someone could tell me what the possible problems? SQL 1: INSERT INTO data_inicio (data_sys, descricao) VALUES (NOW(),'Data de inicio'); Error in…
-
0
votes2
answers5430
viewsHow is a multi-valued attribute represented?
I need to perform a modeling of Google Play as work of univerisdade, one of the requirements of the work is to represent a multivariate. how would that be represented? Would it be a type? ex: Nome…
-
0
votes1
answer2571
viewsReset AUTO INCREMENT and organize item ID
What command can I use to rearrange the ID of all items in a table? The table name is produtos and the column is id. Currently they are this way: id: 1 - 3 - 7 - 8 - 9 - 11... That is, they are not…
-
0
votes1
answer38
viewsFilter data in sql
I have a table clientes with the columns: nome cidade email1 email2 Not all customers have registered email. How do I set up an instruction sql where only returns customers that contain email1 or…
-
0
votes2
answers1867
viewsView with double SELECT from the same table
I need to build a VIEW with three fields, but one depends on the other to be calculated (two of them are from the same table on different lines need "link them"), how do I aggregate these fields in…
-
0
votes2
answers477
viewsCondition in Trigger
About the following Rigger: CREATE TRIGGER [dbo].[TG_TESTE] ON [MINHABASE].[dbo].[TB_DOCUMENTOS] AFTER UPDATE AS DECLARE @ID INT DECLARE @DOC INT DECLARE @QTD FLOAT SELECT TOP 1 @ID = ID, @DOC =…
-
0
votes1
answer429
viewsAdd SQLITE data in Java
Guys, I’m having a problem I’m having trouble solving in Java. The intention is to connect to a database SQLite. But I’m having trouble inserting it. Take a look at the code, please. package…
-
0
votes1
answer96
viewshow to do a query by ordering an ascending and a descending column
need to do a query that searches for a column increasing and in the same query another column descending for example in the result below: item | quantidade carro | 400 carro | 340 dado | 240 disco |…
-
0
votes2
answers234
viewsHow to make a query using SUM correctly SQL
I have the following query: SELECT YEAR(NFDtEmis) AS 'Ano', MONTH(NFDtEmis) AS 'Mes', ItProduto AS 'Produto', SUM(ItQtde) AS 'Quantidade total' FROM NotasItens INNER JOIN NotasFiscais ON NFEmpresa =…
sqlasked 7 years, 3 months ago Igor Carreiro 1,917 -
0
votes2
answers56
viewsHow to select in a table as if it were two records
On the table person has the following information ID | NOME | É_ALUNO | É_RESPONSAVEL 1 | ALUNO | TRUE | FALSE 2 | RESPON| FALSE | TRUE There is another table with the name student, in this table…
-
0
votes1
answer34
viewsHow to do an sql query in Moongodb with php?
How do the following query sql in Mongo? select * from myDB WHERE nm_pesquisa LIKE "%SAO%" AND tp_m = "A" OR tp_m = "H"; I tried it this way but without success: $query = [ 'nm_pesquisa' =>…
-
0
votes1
answer80
viewsSelect data from last database file and select file data from time before last. Compare Data
After fetching two uploaded files, I go to the table to compare the data within them Amid 8: 50 e 23: 50 (with an interval of one every hour) it performs a check in a file of that bank that I call…
-
0
votes1
answer63
viewsHow to use PHP variable on other pages
I have a script that brings the results of an sql search as follows: $sql = (...); $result = $db->query($sql); while ($obj = mysqli_fetch_object($result)) { $ids = $obj->id_prestador.","; } If…
-
0
votes1
answer201
viewsSlow Query - SQL Server 2012
The query below is taking on average 30 seconds to execute. I know that very likely can be the various or and like, but I am searching from the log table and not always the id will be the same, why…
-
0
votes2
answers76
viewsHow to use Firebird 2.1 > ABS in Firebird 2.0?
I have a client who already has a system that runs on Firebird 2.0 and my system runs on the newest version of Firebird, with this I had to regress the database and has some functions that 2.0 does…
-
0
votes1
answer66
viewsSelect ROW_NUMBER from an excel table
Today I wear SELECT * FROM [Plan1$] To select the Excel spreadsheet data, I would like to know how to select the record row as well.
-
0
votes1
answer315
viewsHow do I sort a date field in mysql?
How do I order decreasingly (select * from tabela order by date desc) a date field inserted by the datepicker script in the format dd-mm-yyyy in Mysql? Note: The dates are being ordered only by day,…
-
0
votes1
answer626
viewsHow to update a field from a Database table using a Stored Procedure?
I basically have a database table, which has a field called DESCRIÇÃO and the table is called Tabela123 I have 10 records in this table, and in the DESCRIPTION field I have the sentences: Hello, you…
-
0
votes1
answer48
viewsSQL in php script
SELECT CAST(REPLACE(CAST(DsXML as Nvarchar(Max)),' xmlns="http://www.portalfiscal.inf.br/nfe"','') as xml).value('(/nfeProc/NFe/infNFe/transp/vol/qVol/node())[1]', 'int') as [qVol] FROM SPDNFE WHERE…
-
0
votes1
answer183
viewsQuery SQL error in PHP
I came across an sql error, but when running the query in SQL Server Studio returns me the normal query. Query that is below. SELECT CAST(REPLACE(CAST(DsXML as Nvarchar(Max)),'…
-
0
votes2
answers1665
viewsLimit Inner Join Result
I’ve been in trouble for a few days. I have a select that does some Inners and should return 3 lines, but one of the Inners has several results linked to the searched result; how to limit this Inner…
-
0
votes1
answer137
viewsFilter data by period
I’m having trouble putting together a sql to my system. I have a table anuencias with a column status. I want to list data where on status contain words "signature", "ready to send" and "cartorio"…
sqlasked 7 years, 3 months ago Smoke Rohden 793 -
0
votes1
answer550
viewsUpdate oracle with separate information
I’m trying to do an oracle update with completely different information and I don’t know how to do it. I want all other campuses to be the same as campus 1, where this id_campus is a Foreign key…
-
0
votes1
answer958
viewsSum with Negative and Positive Numbers - Sql Server
I am trying to sum up positive and negative values in the Sqlserver database, but the same done by the calculator returns a different value. I’m using SUM(NR_QUANTIDADE) The NR_QUANTIDADE column is…
-
0
votes1
answer252
viewsSQL returning error when selecting non-existent field
It has a system that several companies use, but changes in bank tables are not informed. You could create a select that does not return an error by not finding a field recently removed from a table?…
-
0
votes1
answer90
viewsgroup records with the same value as a column
I have a table called shops, this table has: ..., store name and loja_category, example: nome_loja | loja_categoria -------------------------- loja1 | roupas loja2 | brinquedos loja3 | roupas what I…
-
0
votes1
answer166
viewsCount in multiple tables
I have 3 tables I need a query that takes the name of the school, number of classes type A, Qtde of classes type B, Qtde of students who are in classes type A, and Qtde of students who are in…
-
0
votes1
answer343
viewsSQL - Delete records that have a field with the same value as another, only when there is more than one record
I have a product bar code table, I want to delete only those bar codes that are the same as the product code and that have another code besides this one. Table: CodProduto CodBarra 01 01 < não…
-
0
votes1
answer260
viewsGet the repeated records from one column from another column
Hello to all! I am facing the following problem: I want to get the amount of values that repeat in the column disease type from the column of locality, that is to say, take the amount of records…
-
0
votes2
answers459
viewsPage php, Not Saved In Bank ! Why?
The code below is inside a huge page, I need that the value that the person put in "email" is inserted in the variable and so to the bank. I’ve reviewed thousands of different codes but always…
-
0
votes3
answers475
viewsReverse SQL ordering
Code sorting of a select can be done in reverse? Example: As the last number of the first element is less it comes first and for tiebreaker criterion the second seventeen will be checked, just as in…
sqlasked 6 years, 6 months ago Robson Junior 79 -
0
votes1
answer43
viewsPostgresql: Catch amount of errors and hits
I need a query to get amount of errors and hits from this table.…
-
0
votes1
answer45
viewsHow to make foreign table associate fields using select?
In my project I have a function in which searches all the elements of the database and still makes "categoria_id" become "categoria_nome" ordering the field in another table, but when I try to use…
-
0
votes1
answer675
viewsDivision of tables with Count and Sum
I am preparing a query where I have some sums and counts and, in some parts, I need to make a division in a table that I have added or made the count, for example: COUNT(M.ID_MAILING), SUM(CASE WHEN…
-
0
votes1
answer17
viewsMariadb returns null with between dates
Someone already had this problem after updating Mariadb, it seems that he ignores the between... On my server these schemas returns null do not know why. Has this ever happened to someone there ?…
-
0
votes1
answer59
viewsSee how many Products were sold in 2017
I’m having difficulty making this query using BETWEEN, this is the model.…
-
0
votes1
answer36
viewsDifficulty validating the login
I have this code for an application from an online store but since I’m new in php I’m having some difficulty validating the login because when submitting the form it accepts everything you have…
-
0
votes1
answer129
viewsxp_cmdshell how to place folders that have space?
I put a folder in the terminal exec xp_cmdshell 'dir b:\teste\*xlsx*' exec xp_cmdshell 'dir b:\teste teste\*xlsx*' When I add the space it does not find. It is impossible to change the name of all…
-
0
votes1
answer1140
viewsTrigger to upgrade stock
I’m trying to create a trigger to update my stock of products, when the status of my purchase is closed (CF = Closed Purchase). However, it is sending me an error, and I could not identify what is…
-
0
votes3
answers335
viewsAdd data from a sql column c#
My problem is this: I need to sum up the total hours of the employee who are in the bank, already in a separate column. Just to be clear, the hours the employee worked the day are already ready, I…
-
0
votes1
answer472
viewsConsultation to calculate the number of female and male students
In this consultation I would use the GROUP BY? That and the model…
-
0
votes0
answers52
viewsHow to write a text file by clicking on a Datagridview?
I have a DataGridView and by clicking on that DataGridView I have to write a file select comparing one column of a table to another column of another table and what results from that select is what…
-
0
votes3
answers402
viewsHow to do an operation on a Trigger? MYSQL
CREATE TRIGGER aumentarsalario AFTER INSERT ON empregados FOR EACH ROW BEGIN UPDATE EMPREGADOS SET SALARIO = NEW.SALARIO * (NEW.SALARIO*(10/100)) WHERE NEW.SALARIO < 900; END IF END How do I put…
-
0
votes2
answers780
viewsLine break within a MYSQL query
Hello someone can help me with line breaking within a mysql query? The code goes like this: CONCAT('Origem -> ',vEnderecoOrigem,' \r\nDestino ->',vEnderecoDestino) The result: Origem -> Rua…
-
0
votes0
answers36
viewsdelete the records that repeat in the entire table minus 1 column
I have the following data: note that there are some Ids that contain more than 1 record, would like to delete the repeated record whose value is the lowest among the repeated ones the table may have…