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
votes0
answers29
viewsMediator vs CQRS vs Repository
Hello, I’m developing a migration to a new ORM, in . NET, from an application with a complex SQL database, many small tables between them. A very tight system. In order to better organize the…
-
1
votes1
answer43
viewsError when modifying a View column with calculation
I need to insert a calculation column in this view below, but the message appears Msg 205, Level 16, State 1, Procedure Consolidadoestudobasesifix, Line 4 [Batch Start Line 9] All queries Combined…
-
1
votes1
answer300
views -
1
votes2
answers1012
viewsDuplicate keys
** Improving the Post to better understand what happened. Person, good afternoon. I created a table 'client' in sql server and put the email field as vachar(50), Unique and null accept pq by logic,…
-
1
votes1
answer19
viewsRelate Products to duplicated EANS in a relation where 1 product has n EANS. sql language
How could I make the comparison with the EAN of another product without comparing it to the same product... in sql? CREATE TABLE `produto`( `idproduto` INT NOT NULL AUTO_INCREMENT, `nome`…
-
1
votes1
answer28
viewsQuery to insert into a Sqlserver table
Sqlserver, given a table with the fields: id (int), name (nvarchar) and birth (smallDateTime) How can I write a query to insert into this table and then query this data from all table records. Id:…
-
1
votes1
answer1000
viewsConversion from . FRM to . SQL
I have a 300MB database and all I have are the FRM, MYI and MYD files. I need to convert the FRM files first to create the structure of the tables, I have already used the following tools and…
-
1
votes2
answers65
viewsStatement update SQL
Good morning. I have the following SQL running: UPDATE pessoas SET implante = true FROM saida WHERE saida.prontuario = pessoas.prontuario and saida.mes LIKE (date_part('MONTH', CURRENT_DATE) || '%')…
-
1
votes1
answer23
viewsConvert SQL to Laraval Eloquent 5
I’m trying to turn this SQL from the postgres below to the eloquent in the laraval someone has an idea of how it would look? select g.id as group_id, max(g.name) as name, max(g.created_at) as…
-
1
votes1
answer90
viewsUsing Case or if
I’m a beginner in SQL and I’m having difficulty using the CASE WHEN. I have a table called CRM_PROCESSO, in which you have a column with the option of Status, but the answer to this status is…
-
1
votes1
answer640
viewsSQL - IN inside a SUB SELECT with NOT IN - ORACLE
I wanted to make my INSERT dynamic, I don’t need to change the ids manually. I have this script that returns all PRODUCTS that does not have 83 relationship with the EST_PROD_PRECO_CUSTO_EMPRESA…
-
1
votes0
answers51
viewsCustomer SELECT with payment for the last two months (60 days)
I have a TBCLIENTS table where I have the columns: NAME, DATA_PAGAMENTO, FORMA_PAGAMENTO. I need to know the customers who paid in the last 2 months (60 days) in the form of payment BOLETO. How I…
-
1
votes2
answers54
viewsTake only the first record of each condition
Good afternoon! I have the following table: How to get only the first record of each id_uni_sching? That is, I need to get the id_sching 534,382 and 524,075 (First time of each id_uni_sching) ?…
-
1
votes1
answer66
viewsHow to join the select of these 3 tables that have no connection at all?
The image below shows 3 tables, united by Excel. The first is called customer, the second representative and the third is called channel. But I would like to join them in a single select in sql, and…
-
1
votes1
answer35
viewsHow not to repeat data in this query
I did this query, which will compose a view. SELECT DISTINCT US.EMPLOYEESTATUS ,US.EMPLOYEEID ,US.EMPLOYEEFIRSTNAME + ' ' + US.EMPLOYEEMIDDLENAME + ' ' + US.EMPLOYEELASTNAME AS FULLNAME ,US.GRADE…
-
1
votes2
answers48
viewsApply condition depending on value
In the script below, I need to use a condition only if the field is filled (line is commented in script below). If not, this condition should not be part of the query. Is there any way to do this…
-
1
votes2
answers1607
viewsI can not put foreign key in PHPMYADMIN
I have my bank already created in phpmyadmin, are two tables, payments and students. I have seen several tutorials and read various ways of how to put a foreign key (fk_alunos) id_students in my…
-
1
votes1
answer617
viewsGrant permission to a new user in SQL Server 2014
I’m trying to assign permissions to db_datawriter and db_datareader a new user in SQL Manager The following steps have been executed: -- criação do usuário CREATE LOGIN apostila WITH PASSWORD =…
-
1
votes1
answer43
viewsProblem with Join and sub-consumption
I have an exercise to answer, however I can not get the complete solution, only partial ideas, the DBMS used is SQL Server. Considering the Customers, Orders and Order Details tables create an SQL…
-
1
votes1
answer53
viewsHow to Migrate Oracle 11G Long Raw Columns
I need to migrate information from a column of type long raw oracle 11g. CREATE TABLE PROD_IMAGEM ( ID NUMERIC(8), IMAGEM LONG RAW ); CREATE TABLE BKP_TAB_IMAGEM ( ID NUMERIC(8), IMAGEM LONG RAW );…
-
1
votes1
answer290
viewsSQL Query to Group Records in MS-ACCESS
Hello, I would like an SQL command for a query in a Access. The structure of the table is: tbList Id | Nome | Genero | Endereco | Estado | ... The result I would like to group by state and count the…
-
1
votes1
answer21
viewsGroup By - Aggregation error?
good afternoon! Thank you for your time. I’m starting in SQL (and programming as a whole!). At my base, I have several lines for the NRPROT with different prices, low values and different resource.…
-
1
votes2
answers41
viewsVarchar operation in SQL 2014
I am trying to do a less sql account in sql Sever management but this format error. I am wanting to do the months account 202103 - 202101 = 2 months How to solve this format problem? select * ,DPD =…
-
1
votes3
answers121
viewsMAX() returning multiple lines
When running the script the same returns not only the maximum value, that is, the longest time, but the 3 times. SELECT P.CD_PACIENTE CD_PACIENTE ,P.NM_PACIENTE NM_PACIENTE ,L.CD_UNID_INT…
-
1
votes1
answer67
viewsHow to make a query in SQL that brings a count of some results
Next, I am developing a query in SQL and the purpose of this query is to Count the records that reached the value below 99,7%(As I have the data for this already calculated and transformed in…
-
1
votes1
answer81
viewsSearch with group by
Suppose the following table records authors' posts on a blog. An author may have several posts. So I have several repetitions of authors in this table of the different posts that he did. How I…
-
1
votes2
answers289
viewsAdd a column with data in Varchar2 format
I want to sum up the column Value that is of the type Varchar2, I know that to use the SUM() I also have to use the GROUP BY, only that I am not able to make the sum. I don’t know which fields I…
-
1
votes2
answers159
views -
1
votes2
answers53
viewsHow to update a data when the date entered is equal to the current date?
I’m making a system where the user can schedule posts, IE, if he enters the date and time, the post will be released when the current date is equal to the entered, until then the logic is simple but…
-
1
votes1
answer43
viewsTime mask HH:MM from a number type field using oracle sql for reporting
I have a query that I use to report hours worked, I tried to use to_char and some other examples I found in stackoverflow. SELECT CASE WHEN BC.ENTRADA1 IS NULL THEN 0 ELSE…
-
1
votes0
answers67
viewsVariable is not populated in Procedure
Good morning. I am running the file below, which validates whether the load should run or not, and if it is not possible to run, returns an error message stating why it did not run: declare @dtAtual…
-
1
votes2
answers1538
viewsReturn 3 months previous from day 1
Every Friday I need to generate a report that brings me transactions made in the last three months. However, I have to pick up from the 1st of each month, for example, we are in the 9th month, so I…
-
1
votes1
answer101
viewsCOUNT with conditions and selection without WHERE at the end
In my table I have 3 columns: id(INT) auto increment tipo(INT): the values are 1 or 2 id_usuario(INT) I need a means without the WHERE at the end to know if there is a user-specific data, and if…
-
1
votes1
answer28
viewsReturn three different values between two tables that have no relationship in Mysql
I have a database with 3 tables, where relationships and attributes are distributed this way: Precise Retornar o nome, data de nascimento e número do cartão das pessoas em ordem decrescente pela…
-
1
votes1
answer20
viewsCompare SQL Server users to AD users
I need to raise users of an instance that no longer exist in the AD for cleaning these. Is there any way to compare AD users with windows Authentication users of an SQL instance?
-
1
votes0
answers44
viewsAPP terminates unexpectedly on smartphone
Below is the code and the logs. I try to run, but always closes the app unexpectedly. It closes without showing the error image or inserts in the bank. package... imports public class Cadastro…
-
1
votes1
answer401
viewsLeft Outer Join Pulling Only Contained Data
I’m trying to do this research to know how many children and pregnant women each Victor meets but only this pulling the families that have pregnant women even putting the blessed LEFT OUTER JOIN, is…
-
1
votes1
answer225
viewsselect distinct in temporal table sql server
I have the following code: (is from a table that the representatives have the same code, which generates duplicated values, I solve this by taking the most current representative, in short the last…
-
1
votes1
answer45
viewsSql using left Join
I have the following tables: TB_ESTOQUE |PRODUTO|QT_DISPONIVEL|COD_FILIAL| |0856322| 5 | 41 | |0856351| 2 | 41 | |0856322| 9 | 114 | |0856720| 3 | 20 | TB_FILIAL |COD_FILIAL|COD_LOCALADM| | 41 | 114…
-
1
votes1
answer28
viewsUpdate the last record with WHERE MYSQL
I wanted to make UPDATE in the last record of the table, where the agent column is equal to "4827" I tried to use this way but error occurs: UPDATE login_agent SET data_hora_login_saida = 'DATA_FIM'…
-
1
votes2
answers324
viewsSQL Select return only one of several
have two tables. Table "user" which has 5 lines and 5 users. is the "location" table that has 20 records, using 5 Foreign key of user table ID When I use this select I made select u.nome from…
-
1
votes1
answer240
viewsQuery joining two tables and filling in fields conditionally
I’m a beginner in SQL and I was wondering if you could help me with a question. I have two tables, one is called Cadastro_func and the other Cadastre. The 'Func_register' has the columns: 'Nickname'…
-
1
votes1
answer182
viewsSelect with PIVOT always returns null
I’m trying to do a query using the pivot based on this link insert link description here, but without success, as it always returns 2 Null lines: Query: DECLARE @registros as table ( ID int, Campo…
-
1
votes1
answer179
viewsAdding +x to each record returned in a SELECT
For example, in a select in the bank, will be returned 5 records: SELECT * FROM esc_usuarios WHERE usu_indicador_codigo = '" . $_SESSION['codigo'] . "' AND usu_situacao = 'ativo'" Then I want to…
-
1
votes1
answer720
viewsHow to add sql values in column
I have the following sql code: select PS.PatSldBemValResidAnt ,PS.PatSldBemValDepAcum ,Sum(PS.PatSldBemValDep) PatSldBemValDep ,Sum(PS.PatSldBemValResid) PatSldBemValResid from Pat_Saldo_Bem as PS…
-
1
votes1
answer75
viewsHow to set only one row of the column in which all values in this column are equal?
I’m trying to set the column ocupado just one line at a time, something like: update suite set ocupado = 'S' where tipo = 'i'; But this instruction changes all rows in the column ocupado where tipo…
-
1
votes0
answers302
viewsYou have a syntax error in your SQL next to’T FOREGN_KEY_CHECKS=0' in line 1
I don’t know much about databases, so my knowledge of sql is minimal. A friend passed me a db so that I could edit and update the data of this (something that seems simple to me), but when trying to…
-
1
votes1
answer110
viewsACCDB + PHP grab column name and table
I will upload accdb files in the database to make an import of clients in my system, in a CRM that used I could upload this file and automatically already showed the columns to be able to link with…
-
1
votes1
answer90
viewsInner Join with Where and multiple tables
I am mounting a query, where I need to Join between two tables (because the data will be in the main B but not in the complementary BC) and a third table that necessarily need data, which will…
-
1
votes3
answers770
viewsSend data to Database according to <select> tag via PHP
I’m making a form to send some data to the bank, to expedite a process, my question is the following, I have 5 systems that I need to update, so I made a select html. I need to send each option of…