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
-
-3
votes1
answer357
viewsPass a subquery of the FROM clause to the WHERE clause
I have the following query with a subquery in the clause FROM and I intend to get the same result but using this subquery in the clause WHERE. SELECT base.nome as Aquario, base.localizacao,…
-
-3
votes1
answer1134
viewsUPDATE in two tables
I’d like to make one update using a Inner Join. I tried this: UPDATE m SET m.rua = 'Rua Major Gote', b.desc_bairro = 'Centro', m.id_tipo = '', m.numero = '652', m.CEP = '38700001', m.cidade = 'Patos…
-
-3
votes1
answer693
viewsSeveral UPDATES in the Firebird database
I can create a method that performs several updates in the Firebird database? For example, I want to update the following record, but it would have to be one at a time, have to update otherwise?…
-
-3
votes1
answer110
viewsCan someone help me find the mistake in this create?
CREATE TABLE PedidoProduto + ProdutoPedido ( Quantidade numeric(50), IDproduto int, IDpedido int, FOREIGN KEY(IDproduto) REFERENCES Produto (IDproduto), FOREIGN KEY(IDpedido) REFERENCES Pedido…
-
-3
votes1
answer546
viewsReturn a single line where it currently returns 2 or more
I’m trying to bring a die, but it doubles when I try to do it. It doubles if the PARC_COD is the same, but should only bring the sum of the return value column in a row indifferent to what is next…
-
-3
votes1
answer39
viewsTake 1 record per date, without repeating the date
I have a box system where every time the box is opened and closed every day is recorded on the table, the box is opened and closed several times a day, however I would like to catch only the first…
-
-3
votes1
answer40
views -
-3
votes1
answer56
viewsI can’t save my record
Buneas personal, I don’t know how to handle C#, so I’m doing the program following tips on youtube and other tutorials that I find, but I came across a mistake that I haven’t found how to solve...…
-
-3
votes1
answer43
viewsReturn dates between number of days
I wonder how I do: I want a variable like days then take the result of this variable and select between the dates counting the number of days Some solution or example?
-
-3
votes1
answer58
viewsScore user who accessed the site 4 days in a row
Every time the user enters the system (logs in), their data is saved in the database, including a Timestamp column. I’m at a loss to solve the following problem: if (usuario entrou 4 dias SEGUIDOS)…
-
-3
votes1
answer59
viewsI need an SQL query to only return one data,
For example, I have a table, with 2 columns, Name and Letter. The table Name, the respective names are inserted, and the table letter, only accepts 3 letters, A, B and C. The same name can have all…
-
-3
votes1
answer122
viewsInsert ID into another field of the same table at the time of INSERT
I’m in the following situation, I’ve been searching the net and found similar aids but not what I really need to know and I don’t even know if it’s possible! Come on! There would be some way for me…
-
-3
votes1
answer1329
viewsError Code: 1064. MYSQL WORKBENCH
Hello I’m trying to create the following table: CREATE TABLE produtos( id integer primary key auto_increment unique , nome varchar(255) unique, descricao varchar(255), preco varchar(10,2) , validade…
-
-3
votes1
answer188
viewsProcessing of units of measurement in the database
In a project I will have units of measurement gram/unit/liter. Not that a product I can sell it by gram and liter, if entered 10kg of meat I will give output 10kg of meat how should I treat it? I…
-
-3
votes2
answers81
viewsHow to use WHERE function in column created from a query?
select a.campo1, b.campo1,replace(replace(b.campo1,'-',''),'.','') as resultado from dbo.tabela1 a, dbo.tabela2 b where a.campo1 = resultado I am trying to select above, but it displays error…
-
-3
votes2
answers193
viewsI was given this exercise: "ALL CUSTOMERS WHO BOUGHT MORE THAN R$ 200,00 LAST MONTH"
SELECT clientes.nome,clientes.sexo, SUM(pedidos.valor_pedidos) AS total_gasto,clientes.cidade FROM clientes INNER JOIN pedidos ON clientes.id_clientes = pedidos.id_clientes WHERE sexo LIKE 'F%' AND…
-
-3
votes2
answers162
viewsMYSQL - How to return records that exist in one table and do not exist in another?
I have the npsparticipantes table that receives the id that comes from the contracts table. How do I recover all contracts that are not added to the npsparticipantes table?…
-
-3
votes1
answer134
viewsMy SQL Error 1215: Cannot add Foreign key Constraint!
Well when I’m adding the references he gives this error, the error appears from the 3rd alter table what I do! create database tipoUber_bd; use tipoUber_bd; create table users( CPFUsuario char(11),…
-
-3
votes1
answer51
viewsAverage
Good Afternoon! I need to calculate the average of this calculated column. SELECT RESUMO.CODCOLIGADA, RESUMO.ID_CCUSTO, RESUMO.CODCCUSTO, RESUMO.NOME, RESUMO.DTBAIXA, SUM (RECEITAS) AS RECEITAS,…
-
-3
votes2
answers39
viewsChange value of FALSE TRUE column
I have a Postgresql database and need to change the table Produto with the column Permite_venda. The items are with FALSE and I need to move on to TRUE How should I do? I list all below: select *…
-
-3
votes1
answer21
viewsSql server heritage in Procedure
I’m having performance problems using views mapped in the EPH to use linq for grouping and paging. It would have a way to assemble a procedure basis, where I explained what it would take for all the…
-
-3
votes1
answer36
viewsUndefined function mysqli_connect ()
I’ve tried php.ini, reinstalling php on the computer, reinstalling xampp to "activate mysqli", but nothing works and my online host does not allow php lower than php 7.4. Error presented: Fatal…
-
-3
votes0
answers16
viewsView SQL codes previously made in Postgresql
I wanted to view the code made in the Query Editor of the Query Tool in Postgresql. In Mysql, for example, every time it opens, the codes made previously appear, already in Postgre after closing it…
-
-3
votes0
answers30
viewsSQL: I need my 2nd table with FK of the 1st automatically updated
I have a Sales_order table with Order Number and other information and created a table with FK of the 1st. I want every time a new order automatically falls in the 2nd (Requested) with the column…
-
-3
votes1
answer135
viewsConditional in Mysql clause
I have a select normal SELECT campos FROM tabela_Z WHERE condicoes I’d like that one query add a field that is another query. SELECT campo1, campo2, campo3, (SE houver o id X na TABELA _, = true,…
-
-3
votes2
answers936
viewsjava login screen and Mysql database
I am validating the login of a simple system but giving an error does not login I will send you the code of the class and the moment I try to log in. Lojabd class that validates the user class that…
-
-3
votes2
answers74
views -
-3
votes2
answers108
viewsConsultation with grouping
Good morning gentlemen(s) I have the following problem: [Edited] As can be seen in the image above, there are several fields with the same result (minus the "desric" column). What I need is that in…
-
-3
votes1
answer57
viewsDATE CRITERIA ENTER A SUBQUERY - SQL
I am doing a query that the boundary dates are based on subquerys, I would like to put a condition so that the boundary column is between data1 and data2 follows the query: SELECT PSECAO.CODIGO…
-
-3
votes1
answer41
viewsWhy is my sql command not saving?
I am saving in the database , but time I click on save will not write repeated name that was what I put to validate ,e o botao não salva no sql <html lang="en"> <head> <meta…
-
-3
votes1
answer69
viewsInsert into database in C#
I’m a beginner in the area and I need to make a select in two tables of the SQL server database through C#, as shown below: ("INSERT INTO entrada_2(id_entrada, id_saida, descricao_entrada, data,…
-
-3
votes1
answer40
viewsHow to fix the error ? Error happens when I am trying to insert data into the course table
CREATE TABLE TIPO ( CODIGO INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, -- Código interno (PK) TIPO VARCHAR(32) NOT NULL, -- Descrição PRIMARY KEY(CODIGO) -- Define o campo CODIGO como PK (Primary Key)…
-
-3
votes1
answer56
viewsHow to make two Join Inner in one table?
CREATE TABLE FUNCAO ( ID_FUNCAO INT IDENTITY(1,1), NOME_FUNCAO VARCHAR(100), SALARIO VARCHAR(100), DATA VARCHAR(100), CONSTRAINT PK_FUNCAO PRIMARY KEY (ID_FUNCAO) ) CREATE TABLE DEPARTAMENTO (…
-
-3
votes1
answer57
viewsI need to present the product with the highest gross sales
SELECT p.descricao_prod FROM produto p INNER JOIN venda v ON v.cod_prod = p.codigo WHERE p.preco = (SELECT MAX(p.preco) FROM produto p) I tried with this code, but, it only presents me the product…
-
-3
votes2
answers65
viewsData editing in PHP
Hello, I have a problem in my code that I did not find the problem. When trying to edit the ID 1750 it runs but saved in ID 0, I wonder if my code has any error in this sense, why by clicking edit…
-
-3
votes2
answers59
viewsI’m a beginner in SQL. I need to build an Insert that will validate some fields of the source table and fill in the target table
I know the situation doesn’t make much sense, but the important thing for me is to understand how to "copy and paste" from one table to another according to one condition. The tables are as…
-
-3
votes2
answers58
viewsData conversion in SQL server after using in Where clause?
I need to extract sales from such a date period until such date. For example, between 01/04/2011 and 30/04/2011. I am not able to bring the result of the period in question. In this case, I am using…
-
-3
votes0
answers14
viewsFunctions in Mysql phpMyAdmin
I’m trying to do the following exercise 1 - Develop a Function that returns the name of the liquidator by passing as parameter the identifier of the liquidator. Then use the created Function to…
-
-4
votes1
answer80
viewsAbout JAVA and Heidisql
People I’m starting programming in java,.
-
-4
votes2
answers1849
viewsAdd a line at the end of the query in MS-SQL
I have a query and it returns the following table: I wonder if it is possible to add one more line (in this case to 3) to make the difference between the two years. I wanted a new line that would…
-
-4
votes1
answer146
viewsGood practices with big queries?
Are there good practices when it comes to SQL queries within php? Or is there an alternative to not "smudge" the code with a giant query in the middle? Edit: What I was looking for was just views,…
-
-4
votes1
answer178
viewsSyntax error when testing the query in phpmyadmin
Error solved . Query SELECT i.codiniciativa, te.nome as nome_tema, te.codtemaestrategico as cod_te, p.observacoes as per_obs, te.sequencia as tem_sequencia, p.sigla as per_sigla, p.nome as…
-
-4
votes1
answer50
viewsSelecting a data in a table that is not with you in another
Hello, I’d like to know how you belt a field that you don’t have on another table. logically would be so "selects document code in table x where document code does not exist in table y ";
-
-4
votes1
answer102
viewsSQL tags in query
I am starting my studies in SQL and do not know what meaning of this structure below. I would like to know what are these tags. I am using in Java. I have a file mapper.xml to create queries in…
-
-4
votes1
answer30
views -
-4
votes1
answer167
viewsWhat databases is Apache Atlas compatible with?
apache Atlas supports which SQL and noSQL databases I’m doing a job, and I couldn’t find anything on
-
-4
votes1
answer82
viewsSQL to create fk int in TABLE
Film COD (int, pk) name(varchar 20, not null) birth (datetime, not null) Obs(tinybit, not null) Obs2(int, fk, not null) I thought of something like create table filme ( COD int PRIMARY KEY…
-
-4
votes2
answers273
viewsHow to select only people with a first name
I would like to know how to select people who have only their first name, that is, they have no last name. Example: Nome ---------- Leonardo Roberto Ana Júlio Maria Ana Expected result: Ana, Júlio…
-
-4
votes2
answers240
viewsCompare a field in the same table
I need to double-check the register with the same CNPJ to eliminate duplicates. select needs to bring the code information,duplicate clients name. Bank structure: tabela CADCLI ( codigo, nome,cnpj )…
-
-4
votes4
answers620
viewsHow to round off this number: 3084.08 SQL SERVER?
How can I round this number: 3084.08 to: 3084.09 in sql server?