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
-
1
votes1
answer45
viewsConcatenation of a Select field into the ADDTIME function
"SELECT at.codigoTurma, " "ADDTIME(t.horaInicioCurso, '00:01:00'), " "t.toleranciaCurso, " "t.horaFinalCurso " "FROM AlunosTurmas at " "INNER JOIN Turmas t " "ON t.codigoTurma = at.codigoTurma "…
-
1
votes1
answer233
viewsHow do ORDER BY with information that may vary?
I’m getting a list of articles from a database and I want to have on page one tool that allows me to list them in order of date they were written or in alphabetical order. Here I have my bank…
-
1
votes0
answers41
viewsFormat JOIN result object
[PROFESSORES] id | nome | 1 | Gilson | [CURSOS] id | nome | professor_id 1 | Photoshop | 1 2 | AutoCad | 1 I would like that in the result of my SELECT, the object comes in the format: (Not…
-
1
votes0
answers66
viewsView data in a mysql PHP week range
I am creating a code that will show the tidal table, I have a table with the following fields: Date - Time - Tideheight It is already all filled, I need to make a query and select the data of the…
-
1
votes1
answer191
viewsSelect with Search conditions
I need to make a query where only display results in one condition: # Search the Database $select_sql = "SELECT * FROM users WHERE user LIKE :search OR date_access LIKE :search OR ip LIKE :search…
-
1
votes1
answer92
viewsOptimization of SQL Query
I set up a series of SQL but I’m having difficulty generating something that stress less the server, I ask help from you. Follows the SQL: SELECT '2015-06-10 00:00:00' AS 'Hora', COUNT(id_contato)…
-
1
votes4
answers594
viewsReturn value in SQL Server query
I need this appointment to return 2 instead of A. TIPOUSUARIO is the varchar type. someone can tell me where the mistake is? USE DATABASE SELECT TIPOUSUARIO FROM TABLE UP (NOLOCK) WHERE TIPOUSUARIO…
-
1
votes1
answer528
viewsHow to make an SQL (Mysql) query with medium and multiple INNER tables?
I have an instruction SQL with 5 tables. Note that I make even a calculation of radius. I need to add a new table of evaluations with: cod_evaluation int(11) cod_client cod_supplier general decimal…
-
1
votes2
answers223
viewsSELECT sort by the quantity of another SELECT
I have two tables in MYSQL: account: id apelido_usuario 1 caio 2 manoel 3 josé product idconta status 1 3 1 3 1 1 2 3 3 2 I made a SELECT like this: SELECT * FROM conta WHERE apelido_usuario…
-
1
votes2
answers1980
viewsHow to group results from a row query to columns
Good afternoon, have this query SELECT tblcliente.idCliente, tblclienterespostapre.resposta FROM tblcliente INNER JOIN tblclienterespostapre ON tblclienterespostapre.idCliente = tblcliente.idCliente…
-
1
votes0
answers443
viewsSQL Server Error When Converting Varchar to Integer Type
FOLLOWS THE ERROR Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the varchar value '280-64460-2' to data type int. SQL DONE USE TOXICOLOGICO SELECT NomeUnidadeColeta,…
-
1
votes1
answer749
viewsThe various part identifier "System.Data.Datarowview" cannot be associated
Try { if (cmbFavorecido.SelectedValue != null ) { txtID.Text = cmbFavorecido.SelectedValue.ToString(); cn = conexao.ConectarSqlServer(); cn.Open(); SqlCommand cmd = new SqlCommand("select…
-
1
votes1
answer73
viewsMysql GROUP BY - PHP error
I have a query in Mysql that, in the command line and in Mysql Workbench, is bringing the correct values, but when running it in PHP, the function GROUP BY is grouping more than it should! Here is…
-
1
votes1
answer128
viewsPerform a select and return the emails in a list
My question is this: I am studying C# and I’m working on a student registration project (study only). I made a form to send an email in case the student misses school, only I did not implement the…
-
1
votes2
answers39
viewsDate help in order printing
I have a field in the table that is defined as dtConcat2 timestamp CURRENT_TIMESTAMP and in the insert it takes the date from the server and writes in this field, the problem when I print the…
-
1
votes1
answer1131
viewsPass data through the link - php application
People I’m not able to do something, I’m beginner in php and web programming and I’m trying to make a page to receive the ID of any user through a click on the link: `while($linha =…
-
1
votes1
answer648
viewsHow to display a result using 2 selects
I have two table, Products and Orders. I need to create a combobox for products and when the user choose a product, the page has to display all orders related to the product, if I choose another…
-
1
votes1
answer354
viewsHow to convert mysql search result into columns
Good evening guys, I do not know if someone has been through this, but I need to convert the result of a search in mysql in columns, is not to exchange the rows for the columns, but rather, make…
-
1
votes1
answer44
viewsSelect a list of values and from that list, select the lowest value
I want to select the last 10 inserts of a table and among these 10, return the lowest value. It is possible to do this in a single query? Selecting the last 10 values: SELECT id_relevo FROM relevo…
-
1
votes2
answers321
viewsHow to give a select and bring the top 1 of each group?
I have a table of processes. That is, each time a process is executed, it generates a new line. I want to give a select bringing the last execution of each process. Follows table example:…
-
1
votes1
answer46
viewsSQL query using order by filtering by log
I have the table: | cod | hora | produto | Amostra | Min | Max | |-----|-------|---------|---------|-----|-----| | 1 | 08:00 | 96722 | 1 | 100 | 200 | | 2 | 08:23 | 96721 | 1 | 90 | 90 | | 3 | 08:50…
-
1
votes1
answer143
viewsSelect with subquery
I have the following select: SELECT id_usuario, SUM(CASE p.tp_honorario WHEN 'Mensal' THEN (h.vl_honorario * 12) ELSE h.vl_honorario END) as valor FROM empresa_honorario as h INNER JOIN honorario as…
-
1
votes1
answer996
viewsGROUP BY - Display grouped result using WHERE as a condition in the same table - Mysql
I am trying to assemble a query to search results in a table where I need to determine a condition for one column, group by another and Display a third. The database consists of 6 Tables, 5 of which…
-
1
votes0
answers194
viewsMysqldataadapter Fill giving error
When using database connection in C#, I saw many ways to do. I can insert data into the database very smoothly, but the selection of data is making me gray. Below the code and soon I will explain…
-
1
votes1
answer703
viewsSearch last record of a distinct group
I’m developing a small vaccine control system and I’m having a hard time executing a select. I have a record of dogs, other types of vaccines and a third of dog vaccine, where I group the dog’s id,…
-
1
votes1
answer26
viewsSelecting specific SQL Server values
First thank you for your time! I don’t know much about SQL, I have a question about how to perform a select. I have some tables, follow these as an example: How do I give a select to know the people…
-
1
votes1
answer446
viewsSelect a row where a column has an element of a CSV
I have a table in the database with the following structure: +---------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |…
-
1
votes1
answer512
viewsSub-Select with MAX / SUM / INNER JOIN?
I need to make a SUM within a MAX to return higher product billing within a summary. I got by doing this: SELECT MAX(Faturamento) MAX_Faturamento FROM (SELECT SUM(P.preco * I.qtde) Faturamento FROM…
-
1
votes1
answer475
viewsDuplicate Bulk Records - Run a query for each displayed record
I have a table where only accounts with your type = 'fixed are displayed' What I would like to do is run a query and duplicate all the table Records at once. At the moment I only managed to…
-
1
votes1
answer343
viewsHow to make a Radius calculation in SQL, using Mysql, with two conditions?
Hello, I already do a radius calculation in SQL, using Mysql and PHP, which takes the location of the device (latitude and longitude) and filters the radius according to the location of the device.…
-
1
votes1
answer41
viewsMYSQL Operation subtraction fields from the same table with different WHERE?
Hello There is a table with TYPE field and Value, Operation value field output (TYPE = REVENUE) - (TYPE = EXPENSE) in MYSQL in a Select…
-
1
votes1
answer108
viewsSelect hard with date
I’m unable to do the following:how to return the time in minutes or hours that a certain WORTH occurred in the table below? Example: how long did the WORTH greater than "23" on 01/05/2017? and if…
-
1
votes1
answer2907
viewsSelect to count quantity per column
How I make a select that returns the amount of equipment repeating, and the first and last date of these records? Equipamento | Data | Causa | B 01/01/2017 x B 03/04/2017 Y A 05/01/2017 Y A…
-
1
votes1
answer107
viewsSimulate Database Update with Select
How I could make a select in the table below (Mysql) to solve the method (Java)? re data is_folga 10 01/01/2017 0 10 02/01/2017 0 10 03/01/2017 0 10 04/01/2017 0 10 05/01/2017 1 10 06/01/2017 1 10…
-
1
votes1
answer37
viewsUpdate the remainder of a table from the data contained in a row
The figure below explains well what I want to try to do (and what I tried to do but it didn’t work): That is, I need to update some rows of a table with the same data contained in a row…
-
1
votes1
answer132
viewsMerge two IF or more
I need to unite some if's and I’m having difficulties, I’ve tried using with the union, but to no avail. The query I’m running is: IF (select count(Estado) FROM tbl_1 where Estado != 'WIP' AND…
-
1
votes0
answers126
viewsIs it worth using index for table in Mysql that stores chat messages?
Friends, I read several posts about the use of the index in the tables of the Mysql database, its advantages and disadvantages, but I still had a question for my situation. Consider over 300,000…
-
1
votes0
answers57
viewsSeveral Updates from a select RAND
UPDATE `tabela` SET `Relacionar_A` = (SELECT `Relacionar_A` FROM `tabela` WHERE `Relacionar_A`='' ORDER BY RAND() LIMIT 2) I can do the update single, only 1 record from the select. What I would…
-
1
votes1
answer71
viewsHow to Relate a Table to Another Table where the field to relate is an XML
I have an SQL Server database from a system that has been discontinued. In this database, there is a table MOVIMENTACAO and a table EQUIPAMENTO, where would set up a relationship N:N. The problem is…
-
1
votes2
answers44
viewsHave more than one line in the same query
I cannot return the database data when I try to search for more products related to different categories. I am using the following query; SELECT * FROM `app_product` WHERE app_category = 6 AND…
-
1
votes0
answers57
viewsINNER JOIN does not return all records
Talk people, good morning. I have two tables in my bank (client and phone), where some clients have several records and others none. Initially I was having trouble "nesting" all the phone table…
-
1
votes0
answers119
viewsUPDATE command on a JSON
Good afternoon, everyone, I’m trying to update a column of my table, but this column stores a JSON Object, only that for this I need to make a where with a JSON also. This one is how the data is…
-
1
votes2
answers121
viewsSQL Update from another tab
Hello, I’m trying to update the product table using the average unit values of one year in the document table (where the notes enter) and the q instruction I’m using returns with error: UPDATE…
-
1
votes2
answers32
viewsQuery that returns sum where states are equal to X and other clusters
I have a table where contains the sale value of some states of Brazil, I would like to perform a query that returns me the sale value of the states of SP and RJ, and for the other states he returns…
-
1
votes0
answers31
viewsSelect with 2 Inner Join returns no result
I have a relational database that has 3 tables: tb_functionaries, tb_licencas and tb_tipo_licencas, each with their respective primary keys. The tb_licencas table, however, has the keys of the other…
-
1
votes0
answers35
viewsCopy tables to another bank while maintaining relationships
I’m trying to send some records from one bank (bank A) to another (bank B) that contains the same structure. They are records of 3 tables, 1 table(patient) contains MAIN records and the other 2(file…
-
0
votes1
answer35
viewsMysql Query - Transfer
I have the following appointment: SELECT despesa.codRequisicao, despesa.histDespesa, despesa.despesaPassagem, despesa.despesaTaxi, despesa.despesaHotel, despesa.despesaRefeicao,…
-
0
votes1
answer101
viewsHow to sum up the days according to a period?
How to sum up days according to a period? Example: +--------------+--------------+--------+----------+ | data_ini | data_fim | codfun | qtd_dias | +--------------+--------------+--------+----------+…
-
0
votes3
answers476
viewsSelect Oracle returning numerous times the same result
My select works and returns the data I need, but it is returning more than 6000 times the same result. How do I get it to return the result in just 01 line. NOTE: There is only one result for this…
-
0
votes2
answers781
viewsHow to perform more than one select for only two fields from another table
I’m not able to select more than one table to display only the ID and name data (table t_cadclients), I’m performing the SELECT of the entire t_cadcontracts table with WHERE in the contract number…