Most voted "select-sql" questions
SELECT is an SQL statement that returns zero or more rows, from one or more base tables, temporary tables, or views in a database.
Learn more…241 questions
Sort by count of
-
3
votes2
answers10563
viewsFormat/mask CPF in Mysql or PDO
I have a field "Cpf" in my table. This field can be of type INT or VARCHAR, in case you need to change to solve my problem. In it there are only numerical values, without the dots and without hyphen…
-
3
votes1
answer1898
viewsHow to return only records without matching in a JOIN?
I have a question regarding the use of JOIN in SQL in this case: I have a table produtos and a table destaques containing the id product. I need to make a query that returns only the records that…
-
3
votes1
answer837
viewsPrefixes in SQL Sentence
In SQL Server it accepts only 4 prefixes in the sentences, e.g.: Select * from pmv.banco.dbo.tabela. In this case, I am using a client Linked server. However, when I reference some field of the…
-
3
votes1
answer336
viewsMount SQL to generate a dataset and popular a Treeview
I have a database here and I want to mount an SQL to generate a dataset in Delphi and then popular a Treeview. The figure below shows part of the seat, but that is the general structure of it:…
-
3
votes1
answer504
viewsMysql select Random with priorities
I have the following scenario, I have a table and I need to select an order by RAND(). But I would like to put some conditions for example: TABELA ID | NOME | IDADE | GRUPO Dice 1 | Hiago | 20 | 1 2…
-
3
votes1
answer481
viewsSelect Distinct returns repeated data when using Row_number
I’m trying to make pagination with SQLServer 2008 as follows: WITH CTEResults AS ( SELECT DISTINCT SolicitacaoServico.AutoId AS Id_Solicitacao, Pessoa.Nome AS Nome, Beneficiario.Codigo AS…
-
3
votes1
answer224
viewsHow to show result between 3 tables?
I have these three tables; table_1 |---------------------| | ID1 | name | |---------------------| | 1 | 'xxxxx' | | 2 | 'xxxxxx' | | 3 | 'xxxxxxxx' | | 4 | 'xxxxxx' | | 5 | 'xxxxxx' |…
-
3
votes2
answers105
viewsQuery bringing all records, and filter the repeated
Have table mov_pallet(some records): movpallet rua altura posicao hora produto data pallet 1.424.959 1 C 4 09:30:07 18.342 02.05.2016 456.074 1.424.960 1 C 4 09:27:07 18.399 05.05.2016 456.182…
-
3
votes1
answer51
viewsI can’t make select
Model: public function exibir_noticia() { $consulta = $this->db->query('SELECT * FROM Noticia_Site_Cairu'); return $consulta->result(); } Controller public function index() {…
-
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
votes1
answer4972
viewsSELECT in VIEW generates sub-query?
I wonder if I make one VIEW with a simple query, whether the view call generates a new SELECT, ie a sub-SELECT totaling 2 SELECTS or whether it only points to SELECT from within the VIEW? I only ran…
-
3
votes1
answer140
viewsQuery - Bring 5 major records
I have the query below, where I need to bring only the 2 largest columns that have the highest values. Today is coming out like this: Conciliacao Extrato Integração 150 140 80 That is, I wanted to…
-
3
votes3
answers924
viewsCan you start a Select (SQL) in the middle of the data table?
Friends, is there any way inside the SQL language (and using mysql BD) where I can start a Select in the middle of a table? For example, I have 500 addresses in the table. I do a search of…
-
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
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
answer45
viewsMYSQL 5.6 does not recognize the query as it should
Greetings! I’m building a query to pick all the times the value was 0 on a given day and the highest time of the previous day. The data in my database is similar to the data I put in SQL Fiddle.…
-
3
votes1
answer66
viewsIntervals between two date columns
The problem is this, I have a table that stores the leave (maternity, health, etc...) of an employee, containing the dates of start and end of leave and other information that is not relevant to the…
-
3
votes1
answer90
viewsHow to limit rows per month in SQL
I have a list of products purchased with date and price, I wanted to organize in a query the ten most purchased of each month, type: mes | nome | total janeiro | arroz | 100 janeiro | feijão | 87…
-
2
votes2
answers3289
viewsSubconsulta Mysql
I have an employee table that has only three columns, NOME, CARGO and SALARIO, I want to assemble a query that brings me all this table and contains in it the highest salary value for the post.…
select-sqlasked 10 years, 8 months ago user8606 19 -
2
votes3
answers104
viewsI need to list a text field with values separated by ;
I have a field text that is being inserted in the same phones in that format: 11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333 And I need to list these fields as a simple select in line and…
-
2
votes1
answer1196
viewsSELECT command denied to user
Error: SELECT command denied to user 'banco'@'xxx.xx.xx.xx' for table 'table' This error only happens in my hosting, is running site perfectly, I am consulting 2 databases in a single query using:…
-
2
votes1
answer2238
viewsError in the query
I’m trying to make a query in the table below, from my database. This query is performed through the method below: public void compraAcoes(float cepf, string codigo, int quantidade) { string cd =…
-
2
votes4
answers3027
viewsLoading the values of a select in my Gridview
My DAL who does the Select and saved in the list type<> using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Web; using MySql.Data; using…
-
2
votes2
answers438
viewsHow to give ALIAS with current "month/year"?
Considering the query below, I need the ALIAS where there are SOMAS, to be "nomeMes/anoAtual" ("ABR/14","MAI/14"...) dynamically. SELECT fornecedor.codigo, UPPER(fornecedor.razaosocial) AS…
-
2
votes1
answer1972
viewsPerform mysql query of two tables via php
Good afternoon guys. I have a problem that I don’t know how to solve anymore. I have the following mysql query in php: mysql_select_db("banco", $conexao); $resultado = mysql_query("SELECT * FROM…
-
2
votes2
answers48
viewsCheck in a table if a user is not registered
Colleagues, I have a table called salas_usuarios, this table contains all users registered in the rooms and another table called users, where I store users. But I would like to check which users are…
-
2
votes2
answers41
viewsLogin form returning error!
I have a login form that returns the following ERROR: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near 'as valor…
-
2
votes1
answer533
viewsSQL Select highest value item
I’m using the Northwind database, and I want to select the category that has the largest number of registered items. I was able to list the category ID and the number of products it has with the…
-
2
votes1
answer63
viewsError in SQL statement
I have the following comic: When I run the following Query: SELECT tbCelula.* FROM (((tbTiposMonitorizacao INNER JOIN tbMonitorizacaoProj ON tbTiposMonitorizacao.TM_ID = tbMonitorizacaoProj.MP_T_ID)…
-
2
votes2
answers342
viewsMask SQL Select return
I’m using the following SELECT to return the Ids one-table. SELECT id, duracao_sessao FROM usuario For ID 1 I want the text "Object" For ID 2 I want the text "Class" For ID 3 I want the text…
-
2
votes1
answer2448
viewsMysql display the sum field with null value
I’ve researched but I can’t find what I need. I have a chart where I have a record of debt and credit releases. These values are in the 'value' field. But I want to display this field in two…
-
2
votes1
answer94
viewsProblems in Mysql query
I’m having difficulty in performing a query between 4 tables, being them. States > Municipalities > Deaths > Population The query is returning the value of the population with a larger…
-
2
votes3
answers180
viewsMysql - Create an alias by concatenating multiple fields
Is it possible to create an alias by concatenating other fields? Ex: SELECT u.nome, u.sobrenome AS nome_completo FROM usuarios u In the example, I want to concatenate u name. and u surname. and…
-
2
votes2
answers45
viewsError in SQL output
Guys, here’s the thing, I’m having to do a select in a bank, where I should look for values that exist between two dates, and that have a specific user. I made the select so: SELECT * FROM `tabela`…
-
2
votes1
answer518
viewsSELECT ... WHERE name LIKE bind_param
I have the following code: <?php $link = new mysqli("localhost", "root", "minhasenha", "meu_db"); $produto = $_GET['q']; $produto = '%'.$produto.'%'; $busca_produtos = $link->prepare("SELECT…
-
2
votes2
answers3313
viewsI need to list the amount of an 'X' product that each customer bought
Below follows the structure and relationships of my database. I tried to use the code : `SELECT `cliente`.`Nome`, `produto`.`Descricao`, `contem`.`QuantItem` FROM `cliente`, `produto`, `contem`…
-
2
votes1
answer1322
viewsSelect grouping by average hour and sum per day
How can I return in a select the daily sum of the value column, Since before adding up I have to average an hour? My table receives the "value" once a second, I need to make the average per hour of…
-
2
votes3
answers86
viewsProblems with SELECT RIGHT JOIN
I have two tables, A and B. Na Table A, I have a column with names of machines (Cutter, Baler, Packer and Rewinder) and in the other column some causes that made them stop (As Lack of Electrical…
-
2
votes0
answers66
viewsTips to optimize Select in SQL. Does the conditional order in Where matter?
Do you have any tips for optimizing Select in sql? If I search a table with over 500,000 or 1 million records, is there any way to optimize my search so that it doesn’t spend too much server…
-
2
votes1
answer456
viewsExtract xml tag from a varchar(max) column
Hello, I have a series of xml records in a varchar(max) column and need to extract the tag <MT_USADA>16 MB</MT_USADA>, for example: <?xml version="1.0" encoding="utf-8"?>…
-
2
votes0
answers139
viewsSelect to group items with related words between the same field
Good morning, I have a database of approximately 40 thousand lines for each product one line. I was using a catalog table (the same as category) where each item (product) that was inserted was…
-
1
votes1
answer2000
viewsCount grouping by week
I have a table in Mysql and am trying to group it by week(it may be week of year) Select count(id),month(data_tarefa), year(data_tarefa) from tarefas group by mes, ano So it works cool, but I would…
-
1
votes3
answers1494
viewsFilter table before applying a LEFT JOIN
I have two tables and I want all the elements of the first - regardless of the condition of JOIN (which characterizes a LEFT JOIN) - but before that I want to filter the second table. For example:…
-
1
votes2
answers1120
viewsINNER JOIN does not return database result
I’m trying to use this code: SELECT * FROM tb_trabalhador INNER JOIN tb_detalhe_trabalhador ON Tb_trabalhador.id = tb_detalhe_trabalhador.tb_trabalhador_id And it returns the blank result. Is there…
-
1
votes4
answers1172
viewsHow to get values separated by "<BR>" in Mysql?
The idea is simple...I need to get values from a table (by performing SELECT) that are separated by <BR> of a STRING field and then store in a table, inserting each separation, a record.…
-
1
votes1
answer1533
viewsList sub-query table with main query
SGDB: Mysql. PROBLEM: I need to somehow relate the subquery (being table and highlighted field Funcionario.codZona1) with the table "Zone", which is in the main query. Is there any way? Table…
-
1
votes1
answer154
viewsBank table does not update
I have in my database some tables they already contain data saved, but I am not able to update this data. I have the method below that performs the insertion of a new item in the table if the table…
-
1
votes1
answer199
viewsTake values that were not used within the bd
I have a table with several product codes: EX: 1, 2, 3 ,4 , 5, 15, 20, 21, 22, 45, 60... I wonder if there is a query to get the codes that have not been used in the records? In the above example…
-
1
votes1
answer945
viewsDoubt about Insert in bank with foreign key using Inline
I have a question, how to insert data in a Mysql table, using English, I have the tables below: I am using the method below to insert: public void inserirCarteira(float cpf, string codigo, double…
-
1
votes2
answers888
viewsError including sum of values in the footer of a gridview
I’m trying to include in the footnote of a gridview the sum of two columns, but I’m having difficulty creating the method that performs this function. I’ve already put the property ShowFooter as…