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
-
0
votes1
answer48
viewsCreate a Three Table Viewer
How to create a view in mysql with 3 tables being the following structure cliente |id_cliente |nome_cliente produto |id_produto |nome_produto |valor_produto pedido |id_pedido |id_produto |id_cliente…
-
0
votes1
answer453
viewsCalendar Per Week Page
I am developing a Specific Client Schedule But I’m not sure how to schedule a week. The schedule works much more do not know how to page now date_default_timezone_set('America/Sao_Paulo'); $data1 =…
-
0
votes1
answer71
viewsSearch next date in database
I am creating a mysql table containing the date of an event. The question is as follows: if on the present day there is an event it is highlighted otherwise indicates the day of the next event.…
-
0
votes1
answer1026
viewsSelect with max(date), penultimate(date)
I have a chart with product code and date of sale. I would like to make a select by taking the product code, the date of the last sale and the date of the penultimate sale with group by code. It is…
-
0
votes0
answers26
viewssql stored Update Value With value from the previous record in the same table
I have a table with several repeated names sequenced by another column called id2 where each 1 of these records has a column with a quantity Example : Name-Quantity-Value2-id2 teste1-1000-0-1…
-
0
votes1
answer917
viewsSearch by string in SQL/ PHP database
Good night, I have the following select which is to fetch users according to their category: $consulta = "SELECT * FROM app_usuarios WHERE cat = '$categ' $categ is the variable I receive dynamically…
-
0
votes0
answers49
viewsFind a record using the value of a cookie
I can’t find a value in the database by a select using as reference a variable from a cookie: $query = "SELECT * FROM carrinho WHERE dono = '$dono'"; However, if you search using the variable text,…
-
0
votes1
answer726
viewsJoin with the same table more than once
I’m having a problem performing a query. The original table calls tbl_operacao, and contains the fields: id, tipo_operacao, idimovel, idproprietario, idlocatario, idseguro, idvalores. When I call…
-
0
votes1
answer814
viewsIs there any way to merge multiple SELECTS into just one query?
I have a page where I will have to make several queries to the bank. At the moment, they are a total of three tables. They are: cadastro, publicacoes and estilo. Currently I do as follows: SELECT…
-
0
votes1
answer181
viewsCreate query to return the smallest possible value
Good night. I need to do a sales report grouped by period and by card. But I do not know how to enter a store and horizontally of it appear the values of each card. Example of how the output should…
-
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
answers16
viewsHow to select most used foreign key?
I’d like to make one SELECT where to select foreign key(idTema) most used Example: That in the example above would be 1 What would that be like SELECT?…
-
0
votes1
answer71
viewsWhere affecting only one field in select
Good morning, how do I make my Where clause affect only one (1) field in my search? For example: $query = DB::table('proventosdesc as proven') ->join('calculo_rh as calc', 'proven.pessoaId', '=',…
-
0
votes2
answers102
viewsHow to take the last inserted values from two tables, and sort them by the last access?
I need to create a select who picks up the id's of two tables, unite them and show me the last record of the two together. I tried so: SELECT DISTINCT p.cod_mobilibus, p.nome, q.dt_acesso FROM…
-
0
votes1
answer41
viewsDOUBT IN A SELECT - SQL
I basically have these relationships: I would like to take the value of the attribute "im_fab_template" of the table "tblImpressora" the code of the attribute "is_cod_printer" of the table…
-
0
votes2
answers617
viewsI have the status and city ID, and now what?
Hello, in a classified site with PHP and Mysql I made through Ajax the insertion of the state and the city. When selecting the state is passed the id and it sends to the file getcity.php that makes…
-
0
votes1
answer224
viewsrelationship between SQL tables
I have the following problem, I have two stocks in my company, so I have two values for the stock, and the stock record looks something like this: as the picture shows, each product has two records,…
-
0
votes0
answers261
viewsMysql hangs when trying to query table with many records (PHP)
I am trying to make a filter where the query is done in a table where the id of the last record is in the number 468.466. In the filter, I need to make a comparison with a View, which has your id…
-
0
votes1
answer41
viewsReturn amount of dependents per employee
I need to select the Plate, the Employee Name and the Number of Dependents of each Employee, but the result of this query is showing the amount of dependents only for the first employee, and I need…
-
0
votes4
answers131
viewsMAX with LIMIT does not give the correct result
Imagine the following lines in my Mysql database: I want a query that displays the name and age of the person who has the highest age in the table, for that I did this query: SELECT nome, MAX(idade)…
-
0
votes1
answer56
viewsPHP | MYSQL Error: Operand should contain 10 column(s)
I am trying to develop a Query where, need to be Consulted in 6 equal tables if there is any specific value. Here is my Query: SELECT ( CASE WHEN (SELECT * FROM sala1 WHERE aluno =…
-
0
votes2
answers3407
viewsError: 'Executereader: Connection property has not been initialized. '
I need to make an access to a database where I put the data myself, the insertion part is working, but now I need to "take" the data again when I click on the button, only it does not matter the way…
-
0
votes1
answer26
viewsResult equal to the last two characters of the records
I tried to create an SQL for MYSQL to query only the records containing the last two characters, I did so: <?php $query = "SELECT * FROM `veiculos` WHERE `placa` LIKE '07%' ORDER BY `modelo` ASC;…
-
0
votes2
answers82
viewsAdd decimal values in Mysql
I have the following query: SELECT SUM('ValorTotal') AS Pagos,StatusCadastros FROM pe_cadastros WHERE StatusCadastros = 'A'; On the field ValorTotal, who’s with the guy Decimal(7,2) has 02 values:…
-
0
votes1
answer46
viewsReturn average cost between partially equal products
As exemplified in SQL Fiddle, given the tables, the data will be returned as follows: nome | descricao| tipo | custo| ult_lancamento | entradas | saidas…
-
0
votes3
answers741
viewsCompare data from two tables
I have two tables: Tabela1 Tabela2 +------+----------+--------+ +------+----------+------------+ | id | idCidade | bairro | | id | idBairro | logradouro | +------+----------+--------+…
-
0
votes1
answer89
viewsSubquery with mysql with two tables
Guys I’m trying to do a subquery in Where as a condition to list the average hours worked greater than 20 and the title of the codProj with 2 tables Following the code: SELECT…
-
0
votes3
answers196
viewsHow to select to find a record between two values?
I have a table with the following values # valor_min vlr_max juros 1 0 1999 0 2 2000 2999 1.2 3 3000 3999 1.3 4 4000 999999 1.4 I need to consult this table with the value ex.: 2500,00 find the…
-
0
votes1
answer44
viewsMYSQL - select that returns everything you have before a '-' or '/'
I have a column in my table 'RG_ORGAO' and there we will find filled rows like this: SSP - PUBLIC SECURITY SECRETARIAT DGPC - GENERAL DIRECTORATE OF CIVIL POLICE DMV - TRANSIT DEPARTMENT I need to…
-
0
votes1
answer25
viewsHow to decrease values in the database of another table, after performing an Insert
$sql = "INSERT INTO `saida` (`nomeProduto`, `quantidadeProduto`, `pa`, `setor`, `dataSaida`) VALUES ( '$nomeProduto', $quantidadeProduto, '$pa', '$setor', '$dataSaida')"; $inserir =…
-
0
votes1
answer299
viewsHow to select multiple data from related tables
I created three tables in the student database, book and loan, I would like to list all the books that were loaned to each student, however, when the student borrows more than one book the command I…
-
0
votes1
answer44
viewsWhy is my WHERE statement in Mysql not working?
I have the SELECT below, and in the WHERE clauses the amount of credit would only be shown if >= 2, but even putting the condition, shows me everything. (fornecedor_credito.qtd_credito >= '2')…
-
0
votes1
answer168
viewsphpmailer is not taking the values from my database
I’m trying to recover e-mail and password, where: $o_email = $_GET['email']; $celular = $_GET['celular']; Receives via URL the user’s email or mobile phone. But I am not able to get these recovered…
-
0
votes2
answers815
viewsSelect averaged in minutes - Mysql
Below is a query returned in a table of my database (Mysql): What interests me are the Timestring, Varvalue and id columns. Every 5 seconds on average an Insert is made on my system. I have 1 month…
-
0
votes3
answers103
viewsGet the same result from a query with Join
I have researched on some forums, consulted my books and looked in other sources, but I did not find anything to solve my problem. I have a query that queries the open value in a given table: select…
-
0
votes1
answer114
viewsSelect result, and show only if all are equivalent
I’m maintaining a database, and I’m in the next situation; in the bank I have 5 columns in a table, are: ID(PK)|Idticket|Result|Prestadoconta|Date I have to filter for the user to see, only the…
-
0
votes1
answer36
viewsHow to select and assign the quantity
I’m trying to use mysql to select two tables and assign the number of rows to a field for example I have two tables: Grupo, Pessoa I want to make a Join in the Group table showing the number of…
-
0
votes2
answers30
viewsMysql Help to Return Unavailable Days for Scheduling
I have 2 mysql tables that represent days unavailable for scheduling: Table Holidays: id, day (date), name Table special_days: id, day (date), will_work(Boolean) In the querie I need to select the…
-
0
votes0
answers109
viewsHow to make select mandatory? and also select by default the first available option?
I have a system in php that generates selects according to the database information, in case I would like to make these selects mandatory because if they do not go unnoticed and also always leave…
-
0
votes0
answers422
viewsHow to align the Select result
I’m drawing up a report, where I take a person’s name, and what days they work. I was able to make that select, but I need it to stay that way: [JOÃO - SEG/QUART] [MARIA - TERÇ/QUINT] [JOSÉ -…
-
0
votes0
answers35
viewsHow could a SELECT perform better with multiple INNER JOIN
I have a SELECT with several INNER JOIN and some functions such as replace, if.. That one SELECT takes all the information I need, but it takes too long. Is there any way to optimize this SELECT?…
-
0
votes1
answer46
viewsError in select search
I can’t return the value inside my Arry always returns 0 Read public class Read { public ArrayList<RespostasAguaCasa> getLista() { SQLiteDatabase db =…
-
0
votes1
answer54
viewsSelect do not return repeated based on a column
I came across a situation where I have a register of customers who may have more than one address in the related tbEndereco table and an address may belong to more than one customer. But when…
-
0
votes2
answers215
viewsProblem inserting data into a table containing foreign keys
Hello, everybody! Well... here’s my problem: I have a Mysql database that has 3 tables (Client, Event, Equipment). The event table has two foreign keys, the first of them referencing the id of the…
-
0
votes1
answer56
viewsView most current sql server 2008 record
I am trying to get the only last record (last sale) of each customer and I am not succeeding. I tried several ways, but nothing.. Only returns all sales from the date. Follow my query. I appreciate…
-
0
votes2
answers517
viewsSelection top 3 Where distinct
Good afternoon, you guys. https://stackoverflow.com/questions/1925176/sql-server-2008-top-10-and-distinct-together I need a help, I tried to see in the above section but could not solve my problem.…
-
0
votes1
answer111
viewsSQL Server 2017 - SELECT with Duplicate Metadata
I made a select using metadata, but the result of my selection brought me something like 'Cross Join'. Even using GROUP BY and DISTINCT returns with duplicate values. I would like an help to return…
-
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
votes1
answer201
viewsError Mysql PHP connection
Good evening, everyone, I am trying to connect my wordpress application to the remote database, so I can list users within the application. I already tested some things between some researches, but…
-
0
votes2
answers198
viewsDisplay Welcome Screen with User Name in PHP page
Good afternoon. I’m trying to implement on a page PHP a welcome message after a login. I would like to display the name of the user who has just logged in through a variable php. The login screen…