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
votes1
answer289
viewsLockar SELECT when I do an UPDATE - Sqlserver
Let me give you an example of what I’m doing, but the question really is at the end. I have a table with 4.100.000 records and I am creating a robot that reads this data and exports it to MYSQL (not…
-
0
votes0
answers25
viewsShow only reservations of the logged-in user
I was wondering how can I show only the reservations made by the logged in user, because I tried a lot of code and none of them worked. I tried declaring a Session with the ID, which even caught,…
-
0
votes1
answer270
viewsandroid.database.sqlite.Sqliteexception: near "SQL": syntax error (code 1): , while compiling: SQL * FROM Employers WHERE id =?
I’m trying to do the SELECT below passing a value as parameter in the query, only it keeps giving the same error. android.database.sqlite.Sqliteexception: near "SQL": syntax error (code 1): , while…
-
0
votes0
answers62
viewsHow to take variable script and insert into a php database?
I have a select field according to the code below: <select id="teste"> <option>oie</option> <option>tchau</option> I have a knob to run an Insert in the database…
-
0
votes1
answer131
viewsHow to enter the PK value of a table in the FK of another table
I created a table usuario using: CREATE TABLE usuario( usuario_id int NOT NULL auto_increment PRIMARY KEY, nome varchar(200)); Then another table using: CREATE TABLE image( id int NOT NULL…
-
0
votes1
answer42
viewsInsert Mysql Database
I need it to be inserted into the Mysql Database (table fotos) the path that is defined as $target_file_name. I believe the mistake is probably at the moment of INSERT. Filing cabinet conexao.php:…
-
0
votes1
answer170
viewsSelect <TD> javascript
I am developing a routine with a dynamic table using javascript, where when opening the routine appears a button 'ADD TABLE' When the user clicks on 'ADD TABLE' the table header appears and an 'ADD'…
-
0
votes1
answer56
viewsSELECT TO REDUCE SEVERAL SIMILAR MYSQL ENTRIES
Good morning guys, I have searched and found nothing very useful. I have an inventory database of my Network Stations. The agent installed on each station sends the installed program names to the…
-
0
votes1
answer80
viewsMysql query - How to select products that were returned before they were purchased using sql only
I have the following table of a mysql product movement database which contains the following fields: id | prod_id | prod_name | movimento_tipo | data_transaction 1 | idProd1 | tv | ordemCompra |…
-
0
votes0
answers308
viewsSQL - Trigger to send email when updated
Good morning, I need help next time: I have a Trigger to email when an update is performed, but I have a problem! Whenever the table has update is an entire grid that is loaded and sends emails to…
-
0
votes1
answer46
viewsJoin show later dates only
I have a table that records steps of a drive. For example: Data - Movimentacao - Produto 2018-01-10 - produzido - id1 2018-01-11 - embalado - id1 2018-01-12 - despachado - id1 2018-01-10 - produzido…
-
0
votes2
answers100
viewsSelect with reference in several tables
I have three tables: PRODUTOS, PEDIDO and ESTOQUE, and I want to list all the stock by order and by products, as shown below: products codigo tipo medida 3020 | unico | 3 3021 | unico | 5 3022 |…
-
0
votes2
answers443
viewsDisplay date correctly on a Jtable
I am unable to display the sql database date type Date in Jtable, the date appears that way: I use the following method to call the table data: public ArrayList<Alunos> read(){…
-
0
votes1
answer127
viewsWhile always returns the last record in sql server
I have a select to bring all the records that have been entered and I need to do a while to go through this select and give an Insert in another temporary table. Only that the while is always…
-
0
votes0
answers23
viewsNullpointerexception
I have a button that takes 2 text fields and sends to Mysql by MVC standard only it is giving a java.lang.Nullpointerexception q do not know how to solve The code of the button private void…
-
0
votes1
answer33
viewsHow do I query the database 10 days ahead and 10 days behind the current date?
Today I can already do the consultation 10 days ago as shown in the query below, I’m just not able to deploy the 10 days ahead of the current date. SELECT `vw_saldobancario`.`contaApelido`,…
-
0
votes1
answer382
viewsCalculating Larger and Smaller Than Average Returns SQL SERVER Error
In the Columns: SUM(CASE WHEN cqd.queuetime < AVG(cqd.queuetime) THEN 1 ELSE 0 END) as 'Qtde < Média' e SUM(CASE WHEN cqd.queuetime > AVG(cqd.queuetime) THEN 1 ELSE 0 END) as 'Qtde >…
-
0
votes1
answer107
viewsDoubt with foreign key
To register the matches of a football championship the following tables were defined: Time ( id int primary key, nome char(20), pontos int, nroVitorias, golsMarcados int, golsSofridos int ) Jogo (…
-
0
votes3
answers721
viewsSelect Distinct is bringing duplicate Mysql data
I need to bring only the last record of each id_face that has in the table imagens, but for some reason it’s bringing id_faces duplicates. Follow my consultation: SELECT DISTINCT(i.id_face) as…
-
0
votes2
answers354
viewsHow to print the result of a SELECT (php / sql) in a specific place in the HTML page?
Greetings, I have a database with a purchase order chart. In my html there is a panel where the number of registered purchase requests will be displayed. I managed to make the SELECT right and print…
-
0
votes0
answers196
viewsConvert RTF to String via SQL?
Good staff I have a small problem, I was asked to do it through SQL to convert a text made through a Richtextbox (VB 6) to normal string, but is that this Richtextbox also serves to by Chinese…
-
0
votes1
answer43
viewsHow to return what the customer bought/paid?
I have the following tables: using JOIN CREATE TABLE tbCliente ( ClienteID INT IDENTITY(1,1) PRIMARY KEY, ClienteNome VARCHAR(50), ClienteTelefone VARCHAR(15), ClienteDataCadastro DATE) CREATE TABLE…
-
0
votes3
answers91
viewsHelp with SQL query with COUNT in multiple rows
Hello, I’m doing the following consultation SELECT p.id, c.nome, v.titulo, count(v.titulo) FROM passageiros AS p LEFT JOIN clientes AS c ON c.id = p.id_cliente LEFT JOIN viagens AS v ON v.id =…
-
0
votes3
answers1359
viewsHow to resolve ERROR: HHH000346: Error During Managed flush [org.hibernate.Exception.Sqlgrammarexception: could not execute statement]
When I try to run my test class I get this error below. I don’t know what else to do, when I comment on the attribute FOLDERAUTOUPDATE class ApplicationItv the insertion in the bank works, but I…
-
0
votes0
answers92
viewsSQL Trigger Updates Stock
LISTA_DE_PRODUTOS create table LISTA_DE_PRODUTOS ( IDPRODUTO numeric identity, PRECO money null, DESIGNACAO varchar(50) null, ALCOOLICO bit null, constraint PK_LISTA_DE_PRODUTOS primary key…
-
0
votes0
answers105
viewsDifficulty making Foreign key with two char fields in Mysql
I am unable to create a Foreign key between two tables, whose type is CHAR: ALTER TABLE hardware ADD CONSTRAINT fk_INC_LOCALIDADE FOREIGN KEY ( INC_LOCALIDADE ) REFERENCES localidade (INC); The…
-
0
votes2
answers267
views -
0
votes1
answer243
viewsError executing update with sub-query
I have the following situation, I need to update several fields based on the return of a sub-query that returns a main code. This subconsultation is done with Join in two tables to obtain the code.…
-
0
votes1
answer95
viewsupdate with self relationship
I have a table called Category, in it I have the attributes ID, DESCRICAO e ORIGEM, I needed to include one more attribute ID_CATEGORIA_PAI, this attribute is an autorelationation with the same…
sqlasked 5 years, 11 months ago Adriano Gomes 711 -
0
votes2
answers50
viewsRmysql - My querys return a list
Hi, I’m working with a database that I usually access with Workbench. To start importing directly into R, I am using the Rmysql library. I can make the connection and find my tables, but when it…
-
0
votes1
answer125
viewsPerforming temporary table comparison
Good morning, I have doubts about how to compare a temporary table with a database table. What I want to return is, among all the data of the temporary table it returns the ones I have in the…
-
0
votes0
answers45
viewsLink condition to a result in SQL
I am stuck on a query due to the return condition of the result. The field CONF4 would have to separate the results according to the UF (MS,MT), as in the following example: CONFIG4 MS MT PRODUTO 1…
sqlasked 5 years, 11 months ago Elton Costa 1 -
0
votes1
answer91
viewsproblem when running select on more than one table in Delphi and Firebird
select works on Firebird, but error -104 on Delphi IBQuery2.SQL.Add('select l.jb_cdempresa, l.jb_cdfilial, p.dtvencimento, l.jb_cdcontacredito, p.vlrpago,'); IBQuery2.SQL.Add('l.jb_cdcontacredito,…
-
0
votes1
answer59
viewsHow to assemble a consult to bring the latest value based on month and year?
SELECT DadosFinanceirosFiliado_Valor, Filiados_Filiado_Id, DadosFinanceirosFiliado_CompetenciaMes, DadosFinanceirosFiliado_CompetenciaAno FROM dadosfinanceirosfiliado t INNER JOIN filiados ON…
-
0
votes2
answers123
viewsQuery with date range with a variable
I’m new in SQL and I’m breaking my head to mount a query that returns the desired results. I have a field whose date format is as follows: 2018-12-13T18:01:16.573-02:00. I have a variable $Período…
-
0
votes0
answers571
viewsFailed connection to database: SQLSTATE[HY000] [2002] No such file or directory
I have this error in Mysql when I try to make the connection. Everything works perfectly when run by localhost, but when running by hosting, it happens: SQLSTATE[HY000] [2002] No such file or…
-
0
votes1
answer532
viewsSELECT DISTINCT in JSON column in postgresql
I have a table that has 2 columns, id (int auto_increment) and Resp (json). In this table I have duplicate values in the column Resp, something like that: id | resp…
-
0
votes1
answer116
viewsPHP+FIREBIRD - Bring table relations result
In Ibexpert the query below brings the data that correctly, but when I use the same query in PHP does not work. SELECT FUNCIONARIOS.nome, CNPJ, cod_funcionario, LOGRADOURO, CONTATO, cidade, estado,…
-
0
votes0
answers163
viewsDifferent Value - Oracle Query
In the query below in the column Valor_Total_da_Ordem is giving a totally different value, far above what was actually to be. The value is giving 55990.62. The correct value being 1333.11. What may…
-
0
votes0
answers165
viewsQuery Sql for provisioning bank balances
Good afternoon, I need to assemble a query that calculates for me in a column the part of the current balance by deducting the amount to pay and adding the amount to receive, thus: residual balance…
sqlasked 5 years, 10 months ago Allan Rafner 1 -
0
votes1
answer1805
viewsSELECT inside a FOR in declare SQL/ORACLE
I need to generate an excel of a table data but I need to do for each my company, so n have to run select changing the company id I thought to do with Procedure but the ones I have and just update…
-
0
votes1
answer223
viewsInsert object data by API into Database
I receive an object with the front data, and in the api ta so the middleware: let no = require('../controllers/InsertNo') let insertNo = (req, res, next) => { dados = [] dados = req.body || ''…
-
0
votes0
answers102
viewsShow data on screen
I’m generating charts and the data comes through a database query. These dice are played in a two-position array. In the "Labels" Script that should return the name of the vendors, in the case they…
-
0
votes2
answers49
viewsHow to simplify this Consultation?
Have the following Question below and I would like to know if there is a way to simplify the WHERE clause SELECT idMembro, dataCadastro, nome, apelido, dataNascimento, telefone, celular, bairro,…
-
0
votes2
answers378
viewsGet the invoiced amount from the previous month
Good evening staff. I am a student beginner in database and would like to take a question for study purposes. Suppose I have the following structure: MES QTDUSUARIOS MUNICIPIO VALORFATURADO 2018-01…
-
0
votes1
answer53
viewsDoubt how to mount a query in Mysql
SELECT `tab_banco`.`nome` AS `bancoNome`, `conta_bancaria`.`conta_apelido` AS `contaApelido`, `conta_bancaria`.`id` AS `idConta`, `movimento`.`conta_bancaria_id` AS `conta_bancaria_id`,…
-
0
votes1
answer51
viewsAdd up the Count results
I am developing a system, and in case I have the following query in SQL (SQL Server), the query is as follows USE REPORT GO SELECT TOP 10 r.[PONTO DE ATENDIMENTO] , r.[CIRCUITO], count…
-
0
votes2
answers2270
viewsProblems with special characters á, ç, à, etc with php/mysql
Hello, I’m performing a get of files from the database to a page in order to be a search bar, but all results obtained are not accepting special characters, such as: ç, á, è. ex: LEGISLATION O APLIC…
-
0
votes1
answer654
viewsHow to make a chart from a python dictionary
I am wanting to make a graph in python pulling information from a dictionary. In my case is the following, I have an initial and final date, I made the difference between the two. If the difference…
-
0
votes0
answers153
viewsSQL query duplicating data
I am using the following command to get the daily total sale by way of payment! So as I present below it works perfectly: " SELECT t.DataDocumento, SUM(t.Valor) Total " + " FROM VendaCliente v " + "…