Most voted "query" questions
Query or *query* refers to the act of recovering data previously stored in a computerised system from certain parameters and/or filters, by means of a specific command or operator.
Learn more…1,160 questions
Sort by count of
-
3
votes3
answers230
viewsSQL Query export for excel
Good, I’m having some difficulties in the result of a query. To fit you is the following, I have a registration application of "unavailability." and I need the following: Every day I have to extract…
-
3
votes1
answer1006
viewsHow to complement this sql query?
I have the following tables below, where schemes(columns) are described in parentheses and the primary key appears in bold: pupil(codpupil, named, dt_ticket, codcurso) course(codcurso, naming)…
-
3
votes1
answer1400
viewsSearch registry by date in mysql
Good night, I have records in my table about phases of the moon 4089 Lua nova 1983-05-12 19:26:41 4090 Primeiro Trimestre 1983-05-19 14:18:16 4091 Lua cheia 1983-05-26 18:48:29 4092 Quarto Minguante…
-
3
votes0
answers378
viewsHow to see the final query that was executed? PHP PDO
I make my appointments as follows: $sql = "Select * From minha_tabela Where meu_campo = :parametro"; $sql = $db->prepare($sql); $sql->bindParam(":parametro", $parametro, PDO::PARAM_STR);…
-
3
votes1
answer537
viewsHow to return more than one column from the same table?
With this SQL I can in my database select and group products by variations that would be in this case different attributes for the same product. Thus, when generating the product view, I have a…
-
3
votes2
answers66
viewsProblem to mount query
I cannot mount a query, the logic is: Select produtos with categorias different products, being the products with more points, so I will have a product of more points of the category X, another of…
-
3
votes2
answers917
views -
3
votes1
answer2214
viewsOperation of group_concat
I have some questions related to the use of group_concat, more specifically for performance. When using group_concat can’t use limit. // a query retorna todos os ID's select group_concat( id ) from…
-
3
votes2
answers86
viewsFetch the various fields from the query
I have this darling: @tudo = Isolated.joins("LEFT JOIN resists ON resists.isolated_id = isolateds.id").joins("LEFT JOIN genes ON genes.isolated_id = isolateds.id LEFT JOIN stats ON stats.gene_id =…
-
3
votes1
answer64
viewsSQL Server 2012, error executing query
Good afternoon, you guys when executing the query below: select PRO_Descricao, PED_Numero from pedido p, item i, produto pr where p.PED_Numero = i.PED_Numero and i.PRO_Codigo = pr.PRO_Codigo and…
-
3
votes1
answer640
viewsMaximum size of sql query text
What is the maximum size of an sql query string? (Maximum query statement) Ex: SELECT * FROM ajuda WHERE (id = 1 OR id = 2 OR id = 3 OR... @Edit: The bank I was using (access) has other limits…
-
3
votes1
answer201
viewsHow to group subtraction of equal fields in Mysql?
I need to make an appointment to return the current balance of the employee. Being that in my modeling I separate the debts and credits of the employee by the type fields 1 for credits and 2 for…
-
3
votes3
answers2883
views -
3
votes1
answer128
viewsMake query not showing some results
I have a table of CPF where the CPF’s registered. I need to make a SELECT where display all registered Cpfs, least 3 CPF’s. Something like: SELECT * FROM cpf WHERE cpf_id <>…
-
3
votes3
answers2223
viewsHow to group for weeks using sql?
I have the following problem . I have several requests , and I want to group them for weeks. I’ve seen several examples ,almost none helped me, I wonder if there is a function that when you put it…
-
3
votes1
answer8135
viewsWays to get bank values with Resultset
Ways to get values from the Java database (JDBC). public static Connection getConnection(){ /* 1. Faz a conexao com a base de dados */ /* 2. Retorna qual banco ira trabalhar */ Connection…
-
3
votes1
answer296
viewsHow to mount a query with optional conditions?
In the example: SELECT * FROM exemplo WHERE ID in(2, 3, 4) He brings if he has these ID at the bank. How to mount a query which places this condition only if the array in PHP have elements? PHP:…
-
3
votes2
answers2382
viewsQuery with dynamic spring data column
I need to perform a select using the spring data @Query, but I need to pass the column name by parameter Example: @Query("SELECT g FROM Grupo g where g.? = ?") Page<Grupo> findTeste(String…
-
3
votes3
answers2295
viewsDoubt when using ON DUPLICATE KEY UPDATE
I’m trying to use ON DUPLICATE KEY UPDATE in my query and for some reason it’s not working. I withdraw the ID and no use ON DUPLICATE KEY UPDATE: values are saved in a new line in the database.…
-
3
votes2
answers1032
viewsBring all records if parameter is different
I have a table contrato with the countryside concluido of the kind tinyint(1), if it is 0 it is not completed and if it is 1 it is completed. I will pass this value per parameter to the query, as I…
-
3
votes1
answer80
viewsFull Text Index for Database facing Ecommerce!
I read several posts here on SOPT about creating índices which left me with many doubts I had, but my main one is about FULL TEXT! In a database that is exclusively aimed at ecommerce, where there…
-
3
votes1
answer2380
viewsExtract data from a BLOB field in Mysql
I have a select where there is a column where this returning me in <BLOB> QUERY SELECT * FROM user WHERE user_id=1 RETURN: id data_cad user_data 12 2017-03-01 21:38:57 <Blob> In the BLOB…
-
3
votes1
answer467
viewsSQL/ORACLE Filter active records in the month
I have a table that records my records where a column records the data_inicial and another column to data_final. I need to generate a report where the user searches all records that were between the…
-
3
votes2
answers247
viewsUpdate two tables with condition
I have the following scenario Two Tables Source Table - Destination Table Both with the same fields [ID] [name] [CPF] The query must go in the [CPF] columns of the two tables, when the [CPF] of the…
-
3
votes2
answers78
viewsDifficulty to query in Mysql
First I’m starting now to mess with mysql I’m very lay in the subject yet I have a table called products_search_items and this table has 2 columns a product_i" and the search_item_id I needed to…
-
3
votes2
answers1100
viewsHow to update or Insert in Mysql in the same query?
In Postgresql you can use the upsert. It checks if the line already exists, if yes it does update, otherwise it does Insert. In Mysql I’m not able to do this, I saw some talking to use INSERT ... ON…
-
3
votes5
answers1137
viewsPostgresql - Remove tuple referenced by another table
I’m having a problem that I didn’t find anything in Google (maybe I didn’t know to ask him) Just imagine the following: I have 11 tables, one call tbl_pai and 10 other calls tbl_filha1, tbl_filha2,…
-
3
votes2
answers505
viewshow to specify values to sort sql server
Good afternoon! Guys, I have the following query below, however, I want to order by specifying some records. Attached for example, is the query generated and I want the column Value to look like…
-
3
votes1
answer49
viewsPresentation of the php query
I need you to help me create a php function that lists multiple tables in a row with multiple columns, depending on the amount of records in the database and the spacing of the tables defined by…
-
3
votes2
answers64
viewsDatabase, display name via ID
Could someone help me. Have the following tables PLAYERS id name nickname status EVENTS id date local_id SCOREBOARDS id evento_id winner loser_id the winning and losing fields, save the player id in…
-
3
votes1
answer1018
viewsError converting from varchar to smalldatetime
In the query below the following error occurred: Conversion of a data type varchar into a data type smalldatetime resulted in a value outside the range. Looking at it, I realized that if I take the…
-
3
votes2
answers83
viewsResult SQL has field and index
I have a PHP function to automate the queries I do: //arquivo funcao.php function executaSql($sql, $param=array()){ try { include "config.php"; $q = $conn->prepare($sql); $q->execute($param);…
-
3
votes1
answer505
viewsUpdate in two SQL Server tables
How do I perform an update at the same time on two different tables? I have a table called Tarefa and another call VinculoReferencia, both have the field Taridinclusao where is this field that needs…
-
3
votes1
answer2389
viewsThe result of the string concatenation is too long
I made a select with the function LISTAGG to concatenate a field of my table, however the error is returned: ORA-01489: the result of string concatenation is too long Query (SELECT LISTAGG…
-
3
votes1
answer115
viewsProblems with select in multiple tables
I’m trying to make the conversion of a select from sql server to Dapper, as it was very big, I’m wanting to leave more lean and readable... However this appearing error in some passages SELECT…
-
3
votes2
answers80
viewsHow to create a condition that does not include the month of December?
I am creating a condition to be executed before the month of December, IE, only runs in the period of january to november year-independent. IF (SELECT TarFechamento FROM Tarefa WHERE TarID =…
-
3
votes1
answer61
viewsHibernate Cache with select Count
Hello! I have a JPQL consultation, with count: public Long quantidadeFaturasAbertasAssinante(Integer idAssin){ return manager.createQuery("select count(f) from Fatura f where f.dataLiquidacao IS…
-
3
votes2
answers999
viewsWhich is more efficient, perform multiple queries or use JOIN?
I have a table X that has my user data, and I need to return to the client the data related to that user in the table Y and Z. I can do it using JOIN or: SELECT attr1, attr2 FROM Y WHERE X_id = id…
-
3
votes1
answer100
viewsMysql and PHP grouping
I need to group a query with a detail, the grouping should be done only when the information is repeated in sequence, for example: id nome 1 lucas 2 lucas 3 marcos 4 lucas 5 marcos In the example…
-
3
votes1
answer278
viewsDecode vs Case Query
We have two ways to work with condition within consultations in Oracle SQL, are they the Case and the Decode, the two have the same function. Allow dynamically and practice how to get a return from…
-
3
votes1
answer653
viewsQuery is executed, but the data does not go to the database
Good afternoon, Guys, I’m studying the PDO and with the following difficulty, the query runs (or rather, does not return me any error), only when I go to the bank has nothing, what I do? pdo = new…
-
3
votes1
answer141
viewscall method in the Laravel query
I have this query here: SELECT p.descr, p.dt_hr, f.id_friend FROM users u JOIN friends f ON u.id = f.id_user JOIN posts p ON p.id_user = f.id_friend WHERE u.id = 1 She returns it to me: I’m wanting…
-
3
votes1
answer50
viewsSQL Problems with query
I am having problems with the following query: SELECT Cliente.Nome, (Reserva.NumeroNoites) TotalNoites From Reserva inner join Cliente on Reserva.ID_Cliente = Cliente.ID_Cliente group by…
-
3
votes3
answers83
viewsSelect different value from "X" name
How do I select in a given column only the different ratings of "X"? I created select below: SELECT top 1000* FROM [tabela_clientes] WITH (NOLOCK) WHERE STATUS= 'pendente' and status_2= 'pagamento'…
-
3
votes2
answers6454
viewsHow to use Sum with subquery
How can I use the sum with a subquery inside? I tried many ways, but I couldn’t. When I try to put the sum shortly after the select main, message appears that I cannot use aggregation function with…
-
3
votes2
answers2319
viewsHow to use like in a comparison of fields in different tables?
How can I use the LIKE for a comparison of two different table fields? I need to compare the first 5 characters of each field. I tried with SUBSTRING and with LEFT, however, the performance gets…
-
3
votes3
answers200
viewsList columns according to current date
I have the following view: select * from chamdosrow It returns as follows: NOME 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31…
-
3
votes1
answer108
viewsIncorrect Usage of UNION and LIMIT
I want my query to return only the first record of the first table (if there is data in it), because the second table has no repeated data. But he returns this mistake: Error Code: 1221. Incorrect…
-
3
votes1
answer98
viewsMount Query to last Google Datastore record
I’m working with the Datastore from Google and I’m unable to mount a Query to return what I need. Situation I have a Entity, keyed {"item": codItem, "item": id}, still within that Entity I have the…
-
3
votes3
answers1436
viewsSQL - Two different WHERE conditions for the same SELECT
I am developing an SQL query which has two different WHERE functions according to the return of a variable. I tried some alternatives but none seem to fit, I need something with this logic: IF…