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
votes0
answers51
viewsValue collection via PHP and Json
I have a select where the data is in a JSON database that are available in the link: https://gist.github.com/letanure/3012978.js The select option works normally , that is, the data appears in the…
-
0
votes1
answer63
viewsQUERY ERROR sequelize Association LEFT OUTER JOIN API NODEJS
I have the following SQL command: select u.name_user, a.type_administrator from users u inner join administrators a on u.id_user = a.id_administrator; and I need to turn this into my API into Nodejs…
-
0
votes1
answer307
viewsCreate a Trigger with JOINS
Good afternoon, everyone, I have two tables: SELECT [CodigoProduto] ,[CodigoDistribuidor] ,[Produto] ,[ProdutoLimpo] ,[NomeMarca] ,[StatusProduto] ,[ChaveProduto] FROM [dbo].[Produto] GO SELECT…
-
0
votes1
answer87
viewsI need the GROUP BY clause read after HAVING
My problem is the following, the distance is the crucial information for my research, and I need to use also GROUP by not to appear several equal products! Then as the group by comes before the…
-
0
votes0
answers42
viewsNaming SQL query tabs
I have a tremendous doubt, I would like to name each query by its content, but I cannot identify how. As a result I have the image below: My code is this one: SELECT a.Marca, COUNT(a.Pedido) AS…
sqlasked 4 years, 8 months ago Viitor Oliveira 17 -
0
votes0
answers301
viewsError in string when connecting sql server database remotely
I’m a beginner in C# and I’m trying to remotely connect my application with an SQL Server database that is on another PC... In this PC has already been configured the TCP/IP port following this link…
-
0
votes1
answer46
viewsMake a database query through an array
Hello, Guys, I got a big question here. I have a query where the user can select if they want to see all(Manager and Managers Jr), Only Managers Jr, or Directly select only one. All Only managers Jr…
-
0
votes1
answer46
viewsButton to insert records into the Database
Great, I’m running a project for my PEF that consists of creating a BD for a company. However, I decided to put a button to add records and when I click to add, the following error appears: Failed…
-
0
votes2
answers48
viewsPlace alphabetical order increasing the description, when the result comes from a search through numerical field
I now have a question, how to put the relationship of employees of a certain function code in ascending alphabetical order. I’ll put the code down: <table align="center"> <tr> <td…
-
0
votes2
answers865
viewsCalculate total amount and total SQL Server value with three tables
Sds, I have a problem, I am not able to group the municipalities in my SELECT. Even with the group by the municipalities are separated. There are three different tables, municipality, product and…
-
0
votes0
answers47
viewsSqldatareader does not return database information
This Datareader below when you type the product code it shows the name of the product in another textbox, works ok, but when instead of searching for the code search by the codebar it does not bring…
-
0
votes1
answer39
viewsButton to enter Records in Database
Good, I am conducting a project for my PEF that consists in creating a Database for a company. However, I decided to put a button to add records and when I click to add, the following error appears:…
-
0
votes1
answer30
viewsButton to enter Records in Database
Good, I am conducting a project for my PAP that consists in creating a Database for a company. However, I decided to put a button to add records and when I click to add, the following error appears:…
-
0
votes1
answer241
viewsHow to make a total disjunction in EER diagram? (Mysql Worckbench)
Hello, I need to deliver a sales system and I need to make the entity "payment form" one of these sub-classes (card, check, billet or deposit), only one per instance... How to represent the…
-
0
votes0
answers65
viewsHow to do an IF/ELSE SQL check
If anyone can help me, I really appreciate... I am beginner and I am not able to develop the following check: If substring (tasks, 9, 1) = S, it should delete only in the Startup tables If substring…
-
0
votes0
answers96
viewsThe column '<column name>' is invalid in the selection list because it is not contained in an aggregation function or in the GROUP BY clause
Hello! In the system there is data collection for some questions and the answers are 0-100. My database has the following tables: Person, Question, Personal. I’m trying to get a select where to…
-
0
votes0
answers47
viewsPROCEDURE WITH MEDIUM
Good morning, everyone, I have the following tables: Create table FUNCIONARIOS (num number, nome varchar2(30), custo_hora number); Create table PROJETOS (cod number, nome varchar2(15), custo_acc…
-
0
votes1
answer25
viewsProblem with Order By Case Over 9 When
How to correctly use ORDER BY CASE WHEN with more than 9 records ? In the example below I am using a case when with more than 9 records and when it arrives at position 10 , 11 ,12 e 13 the order is…
-
0
votes1
answer38
viewsHow do you get the AM out of a date that doesn’t follow a pattern?
My date comes in this format: 3/1/2020 12:00:00 AM (Realize it’s not 01 and 03, it’s only 1 and 3) But obviously it can also come with two numbers on day and month. Ex: 10/10/2020 This makes it more…
-
0
votes0
answers83
viewsHow to identify left and right table in the execution of multiple Joins in SQL?
I’m trying to understand how to read the execution of multiple INNER Joins. If I do multiple INNER Joins my left table remains the same as the first INNER JOIN or the left table becomes the…
-
0
votes1
answer41
viewsLogica in SELECT, display either record
I need to use the rule that is in the if within my select. Main rule is if you have the purchase and the purchase has the approved status I must bring the field with the url of the final product if…
-
0
votes1
answer95
viewsI need to update the value of one SQL table with the sum of the values of another
I need to update the value of the column total_services of a certain number with the value (value value value * quantity) of the table nfpse_detail The command I’m using to try to do this is this…
-
0
votes1
answer24
viewsSQL - How to take a data from a table and insert another preset?
I have a website and need to create a code to send badges, my problem GRAAANDE is, SQL is giving error The idea is to insert in the table "usuarios_placas" the username and the emblem code…
-
0
votes3
answers121
viewsCompare birth date registered in the database to a custom date - mysql
Good afternoon, I am displaying a report, where it is to show customers who own + 60 years. Like me nay own a field idade in the comic book, I had to "discover it" by birth date and did so: SELECT…
-
0
votes1
answer273
viewsCreate temporary table from cursor data
I created a cursor that shows the date of sale and the total sold value of the day. Follow the code: declare cursorteste cursor local forward_only for select data_venda, sum(valor_unitario) as…
-
0
votes1
answer55
viewsCursor does not update Level (SQL)
Good night, I am making a cursor that updates the table level column of schools with the following rules: a. Schools with more than three levels of education are graded with category A b. Schools…
-
0
votes0
answers35
viewsException when executing UPDATE clause on IBM DB2
Hello, I am doing an UPDATE on an IBM DB2 database, and is returning this message: DB2 query node, error in query: Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0100W Não foi localizada uma linha para…
-
0
votes1
answer30
viewsQuery with a different filter for each line
I’m doing a query where, I have 3 columns related by a text filter Where '.' Like %xxx%', where each row of the column has a different filter (a Like %xxx% different). I tried to mount cases but I…
sqlasked 4 years, 7 months ago Feitosafelipe 59 -
0
votes0
answers44
viewsHow to write a temporary table
I need to write a temporary table in sql to use in a subquery. I already have two ways, but they produce unpleasant effects. I imagine there’s another way to create this temporary table, but I…
-
0
votes2
answers36
viewsRetrieve a random value from a predefined number list
Setting: I have a table of users that can contain 1 or N records inside, but for example let’s assume that I have 5 records there with their respective Ids, being them: 4, 23, 59, 17, 33 Is there…
sqlasked 4 years, 7 months ago Igor Carreiro 1,917 -
0
votes1
answer44
viewsHow to define the same INNER JOIN for different fields related to the same table
I have a problem which is this, in the mysql i have a table portaria who has a Fk_key with the table usuario, which is who authorizes, and, a relation N to N with the table usuario for those who…
-
0
votes1
answer41
viewsValidate parameter to disregard left Join
I’m setting up a select, but depending on the value of a come parameter (store = 00000 - all stores), I’d like to skip the "AND p.store = e.store " section on the left Join so that it disregards the…
-
0
votes1
answer47
viewsError while performing max(sum())
I’m trying to solve the problem to find the state with the largest number of cities starting with saint/saint. For that I realized this view: CREATE VIEW SANT AS ( SELECT E.NOME ESTADOS, M.NOME…
-
0
votes0
answers78
viewsI need to create a Mysql Trigger to create a table with the name containing the id of the last row inserted in another table
I would like every time a row was inserted into the chats table, a new table was created. The Table must have the name of the value inserted in the chat_id column of the chats table. Ex: If the last…
-
0
votes1
answer47
viewsProcedure does not update table with NULL value
Hello, I have a little problem. I need my file to update a value that is inside a column in the table "Cashshopdata", at the moment my code is this way. UPDATE CashShopData SET WCoinC=WCoinC+50…
-
0
votes0
answers53
viewsNon-uuid foreign key cannot be implemented
I am creating tables in a Postgre database, in the tables I use UUID as the primary key. For that, I executed: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; So I created the first table with: DROP…
-
0
votes1
answer79
viewsHow to optimize my paging (Datatable) using LIMIT?
all right? I’ve been having some problems for a while, with a table of my system, my table has only 430 records, and whenever I give "F5", perform a INSERT or something like, the "time/delay" table…
-
0
votes0
answers39
viewsI need to make a report that brings the last sale of each product being in SQL
In this report I need to bring only the field with the last output of product X with the respective fields code, desc, client and etc have to do so, but the fields are repeated SELECT distinct…
-
0
votes1
answer229
viewsMYSQL - The used SELECT statements have a Different number of Columns
I have a Mail Query that returns a result that does not contain some data I need, like LOC_NU, LOC_NUM_SUB and MUN_NU. Follow the original NO these fields and no errors: select…
-
0
votes0
answers627
viewsQuery Mysql: Error Code: 2013. Lost Connection to Mysql server During query
I have a Mysql Query that only returns me Error Code: 2013. Lost connection to MySQL server during query. Follows the same: select log_logradouro.ufe_sg, log_localidade.LOC_NU,…
-
0
votes1
answer51
viewsReturn Anniversary of Hiring Weekly in SQL Oracle
I need to provide information on the hiring anniversaries per week. Exemplifying once a week HR will send a message of congratulations to the hiring birthday. I created the following SQL query:…
-
0
votes0
answers36
viewsHow do I dynamically delete a Row with Flask?
Guys I have this code in HTML {% for row in rows %} <div class="card border-success mb-3" style="max-width: 18rem;"> <div class="card-header">{{ row['title'] }}</div> <div…
-
0
votes1
answer88
viewsLink 3 tables in an SQL query
I’m in a quasi-deadly doubt I don’t know will it be possible to run with just one query. I have three tables in the bank where they relate to foreign keys so far everything well I am able to relate…
-
0
votes0
answers50
viewsError when grouping per month with INNER Join using Postgres
Good morning! I’m trying to group my table by month but it’s not working.. I’m using this query: SELECT "Boleto"."id", sum("valor_parcela") AS "volume_operado", sum("spread") AS "spread",…
-
0
votes1
answer211
viewsGroup records and create column in SQL Firebird
I have the following records: |MAQUINA|LOTECA| DTPOST |SEXOCAR|QTDEPIN| |17 MAQ |602121|02/04/20|Fêmeas | 9300 | |17 MAQ |602121|02/04/20|Machos | 9600 | |17 MAQ |602121|02/04/20|Fêmeas | 100 | |18…
-
0
votes1
answer50
viewsSQL - Command for general classification
Hello, I have a table similar to: user_id server_id record date_record 123 333 3 2020-05-10 343 343 4 2020-05-12 133 333 5 2020-05-15 123 333 10 2020-06-10 343 343 12 2020-05-12 123 333 5 2020-05-15…
-
0
votes3
answers47
viewsSql return generation limit
I have this code, which generates number of periods, but I take this return to excel, I can define the amount of returns? I could only bring five, returns, I can limit? DECLARE @serie INT, @ordem…
-
0
votes1
answer311
viewsValidate Cpf’s from a query
Opa gente, to trying to validate the cpfs of a query, are several Cpf"s. I have the following function to validate Cpf, but I’m not getting call-there I’m trying to do it like this: SELECT…
-
0
votes0
answers199
viewsValidate Cpf’s of an sql query
Good afternoon people, I have the code below to validate Cpf and cnpj However, when trying to call the sql function, it does not execute because of the following error: [Code: 6552, SQL State:…
-
0
votes0
answers33
viewsHow to find the increased amount each month?
http://sqlfiddle.com/#! 17/5184a5/3/0 Dice: create table x (id int8 primary key, fk int8, date date, qty int4); insert into x values (292203, 10679, '2019-06-15', 65) ,(300207, 10679, '2019-06-22',…