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
-
1
votes1
answer70
viewsCan you improve these 12 selects where only one parameter varies?
I have an online table with about 3 thousand records. I make twelve selects to list the results per month, ex: select count(campo) from tabela where extract(year from data) = 2016 and extract(month…
-
1
votes1
answer307
viewsBuild school report
I am trying to mount an SQL to display the results of a School Report Card. In the table of notes I have the data as follows Table Notes MATERIA | NOTA | BIMESTRE PORTUGUES | 10 | 1 PORTUGUES | 8 |…
-
1
votes2
answers158
viewsMysql update filtering by due date with tolerance of x Days
I need to update only records that are expired and add a tolerance of x days Example Tolerance of 5 days Today is = 11/10/2016 id= 1 maturity = 10/10/2016 // only update if today was day 15 id= 2…
-
1
votes2
answers2341
viewsGet name through user ID
I have to take my user id and save in a variable the name related to this id, but it is not working ! function inReg() { global $connect; $id_usuario = $_POST["id_usuario"]; $denuncia =…
-
1
votes1
answer346
viewsHibernate does not update information
My problem if it comes to an update unsuccessfully follows the code below. EntityManager manager=JpaUtil.getEntityManager(); EntityTransaction trx= manager.getTransaction(); trx.begin();…
-
1
votes2
answers128
viewsHow to insert primary keys from an X table into a Y table
Hello, good, I’m having a hard time giving insert in the table divide, being that in it I have two FK’s that link the table person.. My question is the following: How to get the desired PK’s and…
-
1
votes2
answers532
viewsEncrypted password check
I’m having a hard time logging in Delphi with encrypted password at the bank MySQL, I can do the registration and encrypt the password in the database through Delphi with the StoredProcedure that I…
-
1
votes2
answers83
viewsSet of WHERE , AND and OR conditions in SQL does not produce the expected result
I’m trying to get some records with a very simple syntax, but it’s not working. I’m doing something wrong and I’m not realizing it. Can someone lend a hand? I need to fetch all records from 2017…
-
1
votes1
answer60
viewsMysql doubt in Select
I have a table of chats on mysql, the record of conversations between users. The fields are. id, id_from, id_to, message Example (My Data in DB): 1, 50, 10, 'Hello' 2, 10, 50, 'Nice?' 3, 50, 10,…
-
1
votes1
answer193
viewsMysql Function returning NULL
My faith works for nothing in this world The SQL is like this: -- Function used to return the remaining space of a chosen folder. -- DELIMITER $$ CREATE FUNCTION tamanhoRestante (_idPasta INT)…
-
1
votes2
answers2073
viewsError creating Mysql Relations using Wampserver
I built the entire database and now I’m trying to do the relations, when I click on the primary key (referential) and click on the foreign key, the following error appears: "Error: Relational…
-
1
votes2
answers584
viewsMake a General Sum with all fields
I have the following tables: tb_product, tb_movement COD_PROD | DESCRICAO | TIPO | |01 | CEBOLA | ALIMENTO | |02 | ARROZ | ALIMENTO | |03 | CARNE | ALIMENTO | |04 | COCA-COLA | BEBIDA | |05 | PINGA…
-
1
votes2
answers202
viewsSQL query with duplicate items
I have this situation and do not know why it happens. When I pass this SQL command the displayed items comes duplicated. What should I do to appear one item each without putting the DISTICT SELECT…
-
1
votes1
answer413
viewsYii2 dropdownlist
I need an example, dropdownlist, where I can dropdown between two sqls, in this case A and B. Below I present a pseudocode. Introduction to the problem: Table sql A id_A id_usuario nome_A…
-
1
votes2
answers908
viewsINNER JOIN in the same table
SELECT Agendamento.E3TimeStamp AS Data,Agendamento.Lote, Produtos_values.name as NomeProduto, Produtos_ValueData.TemplateID AS mp_produto FROM produtos_values inner join produtos_valuedata on…
-
1
votes1
answer83
viewsSUB-CONSULTATIONS IN SQL?
Using the BD below, how would return the name of the person who rented the date '2016/11/17'. Name is in the person table and the date in the loan table. CREATE DATABASE escola; USE escola; CREATE…
-
1
votes0
answers67
viewsRavendb - How to query words ignoring accent
I need to make a person name query ignoring the accent. Ex: in my document I have a record with the name "Leticia". If I refer to "Eticia" the result is empty. The behavior I need is to find the…
-
1
votes1
answer198
viewsHow to resolve Sqlite auto increment gap?
I have a code that erases one Row whole of a database, but there is a problem because I get a hole getting an ID without data (what I deleted) for this being autoincrement, does not delete the ID…
-
1
votes1
answer233
viewsError in MSQLI Insert
I am switching from mysql_to mysqli, everything works(update and delete) more on Insert not saved.... where is the error? Insert archive: include("config/con_mysqli.php"); $sigla =…
-
1
votes2
answers140
viewsProblem with IN condition in sub-select
I have the following problem; I’m trying to do some research and include the value of WHERE major in a sub-select, but the result is always reported as 0, and there are records. Part of query that…
-
1
votes1
answer706
viewsSplit date ranges into weeks
Would have some simple way to extract the weeks given a range of dates, for example: Start date: 01/07/2017 end date: 30/07/2017 Given the above dates how could you automate the extraction of the…
-
1
votes0
answers133
viewsHow to pass parameters for a query in a repository?
I’m creating a series of classes that return listings in Java (Android). I am concerned about the format of the parameters that will be passed. My initial approach has been to pass a Map with…
-
1
votes1
answer69
viewsHow to perform an SQL command that fills several lines
I have a table where there are several records of supplies, now will be implemented a column in this table where will be saved a label that facilitates to find these supplies in the stock, I have…
-
1
votes2
answers99
viewsProcedure for storing in backup tables?
I have two tables, sales and salesProducts because of the volume of information in these tables reading/writing operations are slow. I need to create a database that stores this data (from the sales…
-
1
votes2
answers129
viewsSearch frequency in Mysql tables
This is my question. The system (PHP) has 6 tables (Mysql) identical which are user participation in certain events. Each entry in the table is unique but the data can be repeated in the tables.…
-
1
votes1
answer42
viewsHelp with Web Form Update
I am developing a CRUD system, and am having problems updating registered users. The bad thing is that my browser shows no errors. The problem is that when I edit in some field, for example, email,…
-
1
votes2
answers49
viewsAuto-Complete with database values in input text type
Good evening, I need a code that when entering the input the user will see suggestions below that should be the values pulled from the bank. <input type="text" id="pesquisa" name="pesquisa">…
-
1
votes0
answers39
viewsMysql database insertion problem in php
I am developing a project for the college and I am having some problems to perform the insertion in the my_sql database, my problem is in this excerpt. mysqli_query($conn, "INSERT INTO funcionario(…
-
1
votes1
answer441
viewsProcedure to create database and tables
I need to create a data bank for each client that makes a certain registration, for this I created a procedure to do such a thing. But I came across a small identification problem. When I run the…
-
1
votes1
answer91
viewsLaravel SQL returning with interrogation?
I’m making an appointment at Laravel and it is returning the date with the following value. select `campo` from `tabela` where `campodotipodata` = ? well it returns so the SQL, follows the code in…
-
1
votes1
answer293
views1060 - Duplicate column name 'NULL' in a Mysql query
I am trying to execute this query, and it always gives me the following error: 1060 - Duplicate column name 'NULL' INSERT INTO ce_coins_issued (idc, idu, year, ltr, issuing, status) SELECT * FROM…
-
1
votes0
answers120
viewsFind out how many products I need to sell before reaching the goal
That’s a question that requires logical reasoning, but come on. How to do in SQL can be function, a way to find out how many products I need to sell to reach the goal. For example: I sold a certain…
-
1
votes1
answer213
viewsGet elements from one dependent column of another
I have to make a table where indicate the "name2", "local" and "name" of the animals in greater number in each "name". SELECT DISTINCT OP.nome , OP.localizacao , AD.nome_cientifico FROM C AD , A OP,…
-
1
votes2
answers145
viewsIs it possible in Mysql to update column information in several duplicated rows, leaving only one row with the original value?
For example, I have several rows in a table (which I pulled from an XML of google products, so the same product is presented several times, each for a size of clothing/product) which are referenced…
-
1
votes2
answers1140
viewsReturn last record of each object
I have the following table: imovel ano | id | item | valor Records: 2000| 1 | 201 | null 2001| 1 | 211 | 10 2002| 1 | 202 | null 2000| 2 | 201 | null 2001| 2 | 221 | 17 2002| 2 | 211 | 14 2000| 3 |…
-
1
votes2
answers2462
viewsSelect Chained
Hello, I have a question about a select chained. I found many examples with select * from (select campo from tabela) But I want to define the fields of my query, as below: select…
sqlasked 7 years, 3 months ago Felipe Franco 21 -
1
votes1
answer219
viewsmysql Rank function grouped for a COUNT
I have 3 tables in MYSQL represented here as an example: I need a query that returns a RANK of contracts made grouped by commercial in a given period of time, for example: A query that returns the…
-
1
votes2
answers309
viewsSelect in two tables with data from the first table?
In a table that contains some comments, one of the columns stores the ID of the user who made this comment, how can I recover the data of that user with the ID at the time of making a query in the…
-
1
votes1
answer38
viewsCreate a query by checking two columns
I have a following table: tbl_mission id_misssao assignment status id_warrior id_creator When the user creates a mission, he can add this mission to himself or he can indicate another user (warrior)…
-
1
votes1
answer155
viewsQueries Builder Problems (Query Builder) in Laravel 4.2
Hello, I’m having trouble generating a querie using the Querie Builder of Laravel 4.2, the difficulty arises from the need that the resulting sentences for search in the database are within…
-
1
votes2
answers78
viewsDate problem in Postgresql
I have this query below and I want faturamento, ticket_medio and qtd_pecas, qtd_atendimentos, be divided by the numbers of Tuesdays. Example had 5 Tuesday fairs with registered values in this view,…
-
1
votes3
answers922
viewsHow to create a table (empty) from a selection of other tables?
EXAMPLE: I have two tables : Tabela1 : two-column id_product, product name; table 2 : three-column id_brand, id_product, tag I would like to create a Tabela3 from a selection of the Tabela1 and…
-
1
votes2
answers90
viewsDoubt with group by for last record
I want to make a select that brings the grade data of each student, grouped by student and subject, but I want only the result of the last test of each subject. For example a student can take the…
-
1
votes1
answer165
viewsDoubt about JPQL
I honestly have a certain difficulty with comics, and I need a JPQL that returns only one record. I have a Price entity and a Product entity. I need to bring the last registered price by the user. I…
-
1
votes0
answers60
viewsProblem with View + Postgresql
I have a problem with an SQL query. Follow the example of the query: SELECT col.ad_client_id, adu.ad_user_id, col.ad_org_id, col.c_order_id, col.created, col.createdby, col.updated, adc.updatedby,…
-
1
votes0
answers201
viewsWhat is the difference between SELECT * AND SELECT field1,...?
If I need all fields in the table, there is a difference in performance between using the joker "*" (SELECT * FROM ...) and specify all fields in the table (SELECT campo1, campo2... FROM ...)?…
-
1
votes2
answers501
viewsSQL - query True or False records
I am mounting a simple page that show records marked as blocked by admin. The field is user-block and the options are FALSE or TRUE. I thought the Query would be: "Select * from Usuarios WHERE…
-
1
votes2
answers1073
viewsHow to filter only the date of a field that has date and time set?
I need to create a select in Mysql to filter the month in a table, but the field where the date is set has also set the time, thus: [2017-02-04 10:00:00] How do I filter only the date of this field…
-
1
votes2
answers509
viewsCapture values from one table and insert them into another
I have a temporary table that fills it with the result of a particular query. Now I need to go through the data of this temporary table, row by row, and take certain fields and insert them into…
-
1
votes0
answers364
viewsSQL Select inside a select with condition
I have 3 tables in the database to control a "news portal", where the tables have the following functions: news -> Table with the news gallery -> Table with images used in news relation ->…