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
votes2
answers642
viewsWhat is SQL dialect 1 and dialect 3?
I don’t understand very well with these database deals but it made me curious these SQL dialect. What SQL dialect? What is the difference between SQL dialect 1 and SQL dialect 3? And what’s the…
-
3
votes1
answer922
viewsWhy is it not possible to use an "alias" in the WHERE clause in Mysql?
I need to wear a alias in the clause WHERE, but keeps telling me it’s an "unknown column". I need to select records that have a higher rating than X. The rating is calculated as the following alias:…
-
3
votes1
answer59
viewsDifferent ways to do a query that performs an SQL merge
I learned to do SQL queries with joins as follows: SELECT u.NOME, e.RUA FROM usuarios u, endereco e WHERE e.ID_USUARIO = u.ID ORDER BY u.NOME As you can see, the query searches the name of users and…
-
3
votes2
answers182
viewsHigher value comparing lines
I’m using SQL Server 2008 R2 and I have the following table: ID NUMERO NOME MODELO --- ----------- ------ ------- 1 12 A 777 2 23 A 777 3 05 A 777 4 45 B 999 5 65 C 555 6 30 B 999 7 67 B 999 8 80 C…
-
3
votes1
answer247
viewsConvert SQL to LINQ
How do I convert the SQL below to LINQ? SELECT `clientes`.`Nome`, `clientes`.`Cpf`, `clientes`.`email`, `clientes`.`Id` as clienteId, `cartoes`.`Id` as CartaoId,…
-
3
votes1
answer85
viewsIs there a loop loop behind the code of a CTE?
I’m racking my brain to understand how such a simple command can generate values from 1 to 100. Is there a loop behind a CTE? For in the code below there is a loop WHERE and not a WHILE. WITH…
-
3
votes3
answers68
viewsProblem in select order
I fed this graph But I have a problem with his selection <?php $sql_2_vis = mysqli_query($config, "SELECT data, uniques, pageviews FROM tb_visitas ORDER BY id DESC LIMIT 7") or…
-
3
votes1
answer45
viewsInsert line number in SQL Manager
Hello! I’m trying to see the number of rows on the side of my SQL Manager query, but I can’t find where to put, could anyone help me? I’m getting an error in my query and it informs the line, but…
-
3
votes2
answers638
viewserror: "table sales has 6 Columns but 5 values Were supplied"
I created the following table in sql CREATE TABLE vendas ( ID INTEGER IDENTITY(1,1), Empresa VARCHAR (20), Modelo TEXT, Preco REAL, Kilometragem REAL, Ano INTEGER, PRIMARY KEY(ID) ); I put as key…
-
3
votes2
answers74
viewsSelect to Alias
I’m trying to establish a select to be a alias of a record. I do not know yet if there is such a possibility, could someone clarify me this doubt? ex: select 1 as (select dia_da_semana from ano…
-
3
votes2
answers1174
viewsSum values of several lines under condition
Good afternoon gentlemen, I have a query that returns to me some precise fields of their sum, only that in a condition select adm.adm_ds_administradora as descricao, sum(car.car_vl_cartao) as valor,…
-
3
votes2
answers351
views -
3
votes1
answer51
viewsSQL script, to insert emails into a table, and then change them
I have a script, which does random insertions of emails into a table, after these insertions, I need to find a way to recheck these inserted emails, and change them This is a part of the Script, I…
-
3
votes2
answers122
viewsQuery of similar records
I have a table where I cross exchange data of some professionals, For example, prof A has in common the exchange with prof F, so F has with A as well. But in the permutation report I would not like…
-
3
votes2
answers2934
viewsUpdate using values contained in another table
How can I update a table by setting the value of a field with the same value contained in another table for all records? I have a 'product' table and a 'movproduto' table. I want to update the…
-
3
votes1
answer296
viewsHow to create an index for two tables at once in SQL Server?
I’m pretty sure there’s no way but, come on... I have the following scenario: (I included only the fundamental fields for brevity) - Tabela Venda: - id: int; - cliente_id: int; - cliente_tipo:…
-
3
votes1
answer701
viewsHow to use a COUNT with condition?
I have a table quarto, wanted to return the amount of rooms you have on each floor (the room has an attribute andar), but I don’t know how to get him back from every floor SELECT andar, COUNT(*…
-
3
votes2
answers304
viewsSQL query unifying 3 tables
I have 4 tables that I need to join them in a single query where the result is: nome |COUNT(terrenosDeCadaID)|COUNT(conversasDeCadaID) joao | 2 | 3 maria| 1 | 2 The tables are like this: users…
-
3
votes3
answers4127
viewsCalling attributes of an object in another class in python
I’m a beginner in python and I wanted to know what I call attributes of another object in another class, because in Java, for example: package model; import java.util.ArrayList; import…
-
3
votes2
answers75
viewsAdd or subtract value according to the "release type" (MSSQL)
I have the following query: SELECT MOVTIPOPRODUTO.ID_ENTIDADE, ENTIDADE.NOMECLIENTE, PRODUTO.NOMEPRODUTO, TIPOPRODUTO.DESCRICAO, MOVTIPOPRODUTO.ID_PRODUTO, MOVTIPOPRODUTO.ID_TIPOPRODUTO,…
-
3
votes1
answer90
viewsMerge different database queries
"It is possible to join information from tables of other databases?" This doubt arose when I needed to do a survey make a comparison of data in tables of different stores, Every store has its own…
-
3
votes0
answers445
viewsConnect Firebird via PHP
I have a BD in Firebird on a server other than the web server (PHP). I’m trying to make the connection between them, using the ibase_connect function, but nothing happens, my line in php is:…
-
3
votes1
answer93
viewsHow to merge several updates into different tables?
I have 3 updates, and the tables that I have to give the updates have over 2 million records, so it would be impossible to do one by one, since each takes more than half an hour to run, and waiting…
-
3
votes1
answer580
viewsWhat is the difference between SQL Server, Mysql and other SQL?
I would like to know more clearly what are the main differences between SQL Server, PL/SQL and Mysql, and what are their main strengths/weaknesses.
-
3
votes1
answer268
viewsSelect of Product Structure
Good morning! there is some way to create a query that brings the "product" and all the "Components and Subcomponents" of the structure of this product? Let me try to explain better Structure…
-
3
votes1
answer350
viewsSelect with SUM until sum B is equal to or less than A
I have two tables, products and lots: Products codigo qtdatual Batches codigo qtdlote validade A select example would be: SELECT P.CODIGO, L.QTDLOTE, L.VALIDADE FROM LOTES L INNER JOIN PRODUTOS P…
-
3
votes1
answer258
viewsRandom Records with Criteria
I would like some SQL command for a MS-Access database where I have 500 records and only to return 20 records so random being these (10 FEMININE and 10 MALE) and sorted in alphabetical order by…
-
3
votes1
answer43
viewsSort by month without repeating the year
I would like to add the total sales in the month, but without repeating the year. select EXTRACT(year FROM v.dataVenda), case when EXTRACT(MONTH FROM v.dataVenda) =1 then sum(v.valorvenda) else 0…
-
3
votes2
answers490
viewsUsing case in null field
I have the following structure tb_boletim: |Cod|boletim|dt_enviado| | 1 | N | NULL | | 2 | S |24/08/2018| | 3 | S | NULL | | 4 | S |23/08/2018| | 5 | S |23/08/2018| | 6 | S | NULL | | 7 | N | NULL |…
-
3
votes2
answers44
viewsWhat is the "~*" operator for in a select in SQL?
I saw this line of code in some examples: SELECT * from produto where nome ~*'$texto_pesquisado';" But I don’t know what the function of ~*, I found no explanation. What is it for?…
-
3
votes2
answers738
viewsPHP SQL Inner Join - Show name instead of ID number
I’m having a little difficulty with the INNER JOIN query. I have a table called users and it contains the following fields: First Name Last Name Tipo_fk (Foreing Key) Categoria_fk (Foreing Key) As…
-
3
votes1
answer283
viewsSelect Electronic Point Record (SQL)
How can I gather only the first and last appointment, where a staff member can have X Appointments and even appointments the next day? As the example below +------+--------+-------+-------+ | FUNC |…
-
3
votes1
answer63
viewsUndesirable result - Query SQL
Hello. I’m a problem and I don’t see a way to solve. My table data movement: My query: select avg(m.valor) from Movimentacao m where m.tipo='SAIDA' group by m.data; Man outworking: I cannot group…
-
3
votes1
answer72
viewsCondition of a query with an under-consumption
I need to update the last 110 table records relevo, but my problem lies in the current WHERE. I’m doing it this way: UPDATE relevo SET id_projeto = 157 WHERE id_relevo = (SELECT id_relevo FROM…
-
3
votes1
answer381
viewsCalculation of SQL hours
I need to implement a report of hours worked within a period. My difficulty is as follows: the records of each day are in different lines and because of this, I’m having difficulty to beat the entry…
-
3
votes1
answer219
viewsValidation of string size
I was creating a function to validate large text fields (description, observation, ...), which in SQL will be saved as TEXT, so I basically did this: function($valor, $min = 0, $max = 65000) { if…
-
3
votes3
answers58
viewsField referring to the MAX
I have the following table/fields: Table: PLANS ID (PK) VEICULO (IS REPEATED) DATAINCLUSAO REVISAO (UNIQUE) I need to bring the number of REVISAO of each VEICULO of the latter DATAINCLUSAO. So I can…
-
3
votes1
answer131
viewsColumn for Mysql row
I have the following table: | Roll No | Student Name | Q1 | Q2 | Q3 | |--------------|--------------|--------|------|------| | 1 | Aluno 1 | 1 | 1 | 1 | | 2 | Aluno 2 | 1 | 1 | 0 | | 3 | Aluno 3 | 1…
-
3
votes3
answers97
viewsRelationship between the tables
I have the following tables: TB_ESTOQUE |COD_PRODUTO|QT_DISPONIVEL|COD_FILIAL| | 0856322 | 5 | 41 | | 0856351 | 2 | 41 | | 0856322 | 9 | 114 | | 0856720 | 3 | 20 | | 0856322 | 8 | 128 | | 0856322 |…
-
3
votes2
answers426
viewsSQL command in String Mysql
I am making a precedent that saves a select in a varchar variable. Now I need to run this sql command, how do I do that? I am using Mysql. Procedure: delimiter $$ create procedure eixos_caminhao (in…
-
3
votes1
answer1428
viewsHow to quote a variable for Mysql query
I’m doing a trial, I need to put a variable varchar in the query, but it doesn’t go with the simple quotes, I tried to concatenate like this or something but it’s no use: set @comando :=…
-
3
votes1
answer246
viewsSelection with Dapper using IN clause
My idea is to generate a search in my bank using the clause in through the Dapper. For example: select * from product where CasNo in(@filtro) Remembering that inside this @filtro has a list of Casno…
-
3
votes3
answers800
viewsSpring Data JPA does not recognize the SQL 'Limit' command?
I am creating a REST API, using Spring Boot, which, using data from a table, displays random phrases. Giving a Google, I found that it is possible to generate random results through pure SQL: SELECT…
-
3
votes2
answers417
viewsCount with null value return zero
I made an Insert in a table and now I need to make a select in this table making a Count in a given column. The point is that this column (which I gave the request name) has null value for some…
-
3
votes1
answer1172
viewsCheck whether date is even or odd
I am in need of help with dates in SQL Server. I have a date field and would like to know if this date is odd or even. Because I need to make this comparison to use in another field. I looked for…
-
3
votes1
answer171
viewsINSERT INTO in Postgresql with random values
Hello. My problem is basically a popular table in Postgresql with randomly generated data. As the SQL commands are quite extensive I would like to complement this table gradually. The table has the…
-
3
votes3
answers1854
viewsSQL query to know the sales of a period (year), dividing by month and showing the total of each month and year
I work as a technical support in an automation system, a customer asked if there was a report in the system that showed the total sales of 2018 divided by month and showing the total of each month…
-
3
votes1
answer1310
viewsIn Sql server does "GO" have the same point and comma function?
What is the reserved word "GO" for Sql Server, when generating a script using Sql Server Management is always generated with the reserved word "GO" at the end of the instructions, however if I take…
-
3
votes2
answers372
viewsQt - Check if table is empty in the database
I have an application with a database connection, when initializing the application I need to check if there is any record in the table, if a user should not be registered, when I run the query…
-
3
votes1
answer66
viewsIncomplete sum with JOINS in Mysql
I’ve had a doubt for a few days and I can’t find a solution. I own the tables: swing +------------+---------+------------+----------+ | id_balanco | id_loja | data | dinheiro |…