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
-
0
votes3
answers378
viewsDoubt SQL query d
I am wanting to perform the calculation in sql query where the result is the number of open calls divided by the number of working days chosen period. Ex: They were opened 200 calls in the month and…
-
0
votes3
answers252
viewsReturn the row of a table when the value of Count(field) is 0 in Mysql
I need that even when the search does not generate results, is displayed the value 0, I tried with the following SQL search, but without success: SELECT c.categoria as categoria, CASE WHEN…
-
0
votes1
answer833
viewsHelp with Trigger summing/subtracting
I need help creating a Trigger in SQL Server that takes a value INTEIRO, and two STRING(FK), inserted in a tabela X, and check if the second value is 1 or 2, if it’s 1 she must add up this value…
-
0
votes2
answers677
viewsQuery sql codeigniter
I have a table with dates and I would like to create a query that returns records with dates prior to the current day but I could not assemble this query; follows below my code and BD image:…
-
0
votes1
answer235
viewsMaximum number of rows of a Mysql import
Well, I am making the import that contains all my databases, because I switched from computer, I exported from old and I want to import to new, but when importing I get an error: "tempo limite…
-
0
votes3
answers46
viewsGroup separate table records
How can I get the number of identical names from 2 tables, customer and suppliers. Ex: the result is Name. Qtd Joao. 2 Peter. 15 Michael. 7 The code I have is this. Select nome from fornecedores…
sqlasked 6 years, 8 months ago Daniel Fernandes 235 -
0
votes1
answer25
viewsConcatenate an SQL value
I have a Rigger that updates a certain table of raw material, however it replaces the existing quantity and I need it to concatenate the new value with the existing value, someone could help me how…
-
0
votes2
answers651
viewsSQL query with list in WHERE
I have a query that searches all id’s of a comic. I make a WHILE and put them in $retorno['dados']. Since there is nothing separating them, they are all together. If you return the id’s 41, 45, 50,…
-
0
votes1
answer1114
viewsHow to decrypt records from an SQL column - Query
Good morning! Guys, how to decrypt records from a column in an SQL query. The field I want to decrypt is the coluna MAX(A.Descricao) [Descrição da Última Providência]. SELECT…
-
0
votes2
answers1605
viewsCalculate column date - 6 months of current date (SQL SERVER)
I have a column in db that is D_EMISSAO and in it has a date yyyyddmm. I have to show the data that are related to column D_EMISSAO if it does not exceed 6 months according to the date D_EMISSAO…
-
0
votes1
answer90
viewsConvert a sql to_date to a java date
My problem is the following, I have to take rows of SQL Insert and check whether the formats in the TO_DATE function in these Inserts are valid with a java method. For a 'DD/MM/YYYY' format,…
-
0
votes2
answers1404
viewsHow to give permissions to user groups in Postgresql?
*All registered users who are members of the "ACCESS SITE" will have the same permissions. I created a group of users (Group Roles) in Postgresql called "SITE ACCESS" to put all users (Login Roles)…
-
0
votes0
answers186
viewsSQL script to adjust decimal point of a column - Postgresql
I have a table in Postgresql that has the field IdProduto and Quantidade. The values in the column Quantidade were recorded to the wrong decimal places. Ex: It was recorded 9000,000 when it should…
-
0
votes1
answer32
viewsHow would I show the person logged in at the top of the list
I’m trying to ride a SELECT that displays the person at the top of the list, I did so more is showing her at the end of all "SELECT * FROM usuarios ORDER BY id != ? DESC", I’ll give an example, I…
-
0
votes2
answers67
viewsHow to make a Count work by taking only the fields I want?
How can I catch a field I want doing the COUNT work? select PVN.NFNum, COUNT(distinct CtrlCargaNum) as Qtd from CTRL_CARGA cc INNER JOIN PED_VENDA_NOTA_FISCAL PVN ON cc.EmpCod = PVN.EmpCod where…
-
0
votes1
answer95
viewsSQL SERVER Counting Items from a Calculated Field
Good afternoon, I’m having a hard time doing an item count on SQL SERVER, I need to count a column that MYSELF CREATED, where there is a rule, and there are several errors in my tests, errors in…
-
0
votes2
answers7693
viewsForeach in SQL to put a value in a variable
My problem is that I have a subquery that works perfectly, but for that I have to insert the id I want in the variables. In the variable @mediaKM_mes I select to the table tblAbastecimento by the…
-
0
votes1
answer22
viewsSearch for information not directly related in the Database
I would like to select from a database that has the tables Book, Author and Publisher, the attributes Author name, Last name, Book title and Publisher of tables that are not directly related (so to…
-
0
votes1
answer45
viewsRun Trigger according to the value of a column
I need this Rigger to run when there is an update in the table auction, but only when the column value auc_status is equal to 3. That is, so the value of auc_status is changed to 3, he must run the…
-
0
votes2
answers1413
viewsMysql - Select comparing fields from the same table
I know it’s supposed to be simple, but I’m having a hard time getting through this. I have a table called "enterprise". In this table, I have 4 specific fields that store different ID’s from other…
-
0
votes1
answer3060
viewsError - Query: The sub-query returned more than 1 value
I am new to SQL and I have the following error in my query: "The sub-query returned more than 1 value. This is not allowed when the subconsulta follows a =, != , <, <= , >, >= or when it…
-
0
votes1
answer6413
viewsINSERT and INNER JOIN together in Mysql?
Hello is possible to use the INNER JOIN together with the INSERT? I have a table A with 3 columns X, Y and Z and table B with columns W, X and Y and I need to insert in table A the column W of table…
-
0
votes0
answers173
viewsBest Way to Store Varchar(MAX)
I’m working on an EAD project where I work. There will be simulations with many questions and their respective answers. These questions and some answers are usually quite large and I am storing them…
-
0
votes2
answers256
viewsFirebird sql error and doubts
I own this table code CREATE TABLE news ( id_news INTEGER NOT NULL, title VARCHAR(128) NOT NULL, slug VARCHAR(128) NOT NULL, text TEXT NOT NULL, PRIMARY KEY (id_news), KEY slug (slug) ); That is…
-
0
votes2
answers44
viewsError while performing a SQL filter
I cannot identify the error that is happening in the code below: $bannerguia=mysqli_query($con,"SELECT id, senha FROM conta WHERE senha = '$senhalog'");…
-
0
votes1
answer97
viewsGroup employees by company in query
I’m making a report, where I need to follow the following layout: With the query below, we ended up creating more lines, instead of grouping employees per company: select e.cnpj as cnpj,…
-
0
votes2
answers510
viewsHow to select data from the previous month and year?
I’m trying to search from dates in Mysql. I need to obtain the total sum of a value where the year and month are smaller than those reported in the variable: SELECT SUM(valor_pag) FROM controle…
-
0
votes2
answers222
viewsFormat year on Sqlite
I need to format a timestamp in the following format: DDMMYYHHMMSS I got it using the strftime, example: select strftime("%d%m%Y%H%M%S", current_timestamp) from stream; But this way it shows 4…
-
0
votes2
answers150
viewsDoubt with SELECT in MYSQL database
I need an sql that, in the table below, always bring the last insert to each user. I tried with distinct but it didn’t work. So in the case below sql would bring the results of row 2 and 5. Detail…
-
0
votes1
answer49
viewsCompare field with multiple values from another field
I would like to make a SELECT based on multiple field values [jainscrito] and list only the Ids that are not in the field [jainscrito] I’m trying unsuccessfully $sql = "SELECT * FROM usuarios WHERE…
-
0
votes0
answers52
viewsProblem with cyclic relationship
I have a question: I have a user who submits documents which in turn are read by other users. Is there a problem in this cycle?…
-
0
votes1
answer75
viewsTurn 2 Select Simple into 1
I have the following table PLAYLIST where I have the columns VIDEO and STATUS: VIDEO | STATUS The column status varies between 1 and 0 being 1 for new videos and 0 for videos that have already been…
-
0
votes1
answer77
viewsCommand similar to sql Convert in c#
I have a return in sql that comes as something like 52,451541554. That return, if I convert it with the command convert(datetime, DtCriacao, 103) of sql it turns into a date format, only that I’m…
-
0
votes1
answer1443
viewsDelete record by comparing values between two tables
I have two tables: produtos - id_produto valores - id_produto id_produto would be a column, equal for the two tables. I need to delete the records from the table values, but only those that are NOT…
-
0
votes2
answers60
viewsTrigger with column check
I need to make a Rigger in mysql, but I need it to be executed only when there is an update in the auctions, which change the status to 3 or 4. The way I did below is correct? It is of the type…
-
0
votes1
answer51
viewsSelection of SQL related records
I have two tables, one that calls grupo where groups created for access to an application are stored. For example, if you have in the group CADASTRO_ADMIN, you will have full permission; now, if you…
-
0
votes2
answers235
viewsEnsure query result random sorting
I have the query below, which I use to check IP’s valid collectors in the network for distribution of items for separation: Select distinct IP, USUARIO, trunc(DATA) from PCN_ROMANEIO_ACESSO PRA…
-
0
votes0
answers116
viewsSQL needs CAST to return values in query
Gentlemen I manage an application PHP which uses SQL Server 2008 database. After a server migration from the database queries only work by converting with CAST and selecting one by one on SELECT.…
-
0
votes1
answer295
viewsSelect to pick up 2-column Constraint
I have a PERSON table in it that has the field A and B that form a UNIQUE. I rotate this select to return the name of the constraint: SELECT DISTINCT COL.CONSTRAINT_NAME FROM…
-
0
votes1
answer35
viewsDatabase query between tables
Database has 4 tables tabela 1 |escola|descricao| tabela 2 |matricula|nome|estado| tabela 3 |matricula|escola|posicao| tabela 4 |matricula|diretor|nome I need to do a state search (in table 2) and…
-
0
votes1
answer60
viewsNot bringing the records - Query SQL
Good afternoon! Guys, below is the query that is to bring the amount of active clients in one column and the amount of locked clients in another column, however, when running the query, comes null…
-
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
answer176
viewshow to bring ten best media in mysql?
I have two tables: participants and results. In the table of participants I have idParticipant as pk and name; in the table results I have idParticipante as fk, result and date. For the result to…
-
0
votes0
answers49
viewsSaving file on server
Good afternoon, I am trying to send a php file to the server, but it is not going to the given folder and is getting "loose" in the main folder. And also, instead of the file going to the selected…
-
0
votes0
answers117
views -
0
votes0
answers266
viewsSQL Server Connection
I’m trying to make direct connection to SQL Server, for testing, but at the time of testing "Register" by clicking the button, the app simply hangs, there’s something wrong in the code? package…
-
0
votes1
answer163
viewsSQL comparison with values written in different ways
I am comparing two tables "A" and "B" in which I want to compare values of the columns with the same meaning, but they are written in different ways. Table "A" has the column "Mes_ano" and has…
-
0
votes1
answer67
viewsMy SQL always adds 24 click to each access instead of 1
I have a script that counts the visits on my web pages and stores mysql, however, it is adding 24 clicks to each access, instead of 1. What’s wrong with this code? Look at the script: <?php…
-
0
votes0
answers42
viewsVisits to the website
Hello friends I have this information of my visitors to make a very cool Dashboard, I am wanting to calculate the time of permanence of customers on the site, to each access that the person gives it…
-
0
votes1
answer1582
viewsHow popular in database to perform tests?
I am needing to popular this bank to perform consultation tests for didactic imprint. I already have about 5 students, 2 teachers, but the problem is to popular the exercises manually. There is some…