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
answer51
viewsFill in the name even if the name does not exist in the table
How can I replace the section below, so that the name of the activities of tbl_atividades_por_dep, even if the record does not exist in the tbl_atividades, the first select with distinct is what…
-
1
votes1
answer60
viewsInsert not exist duplicating records
tou with a problem in SQL server 2008 I have to enter an occurrence of the credit card data however the query is not taking place the way I needed. The tables are CREATE TABLE TEMP_DADOS_CARTAO (…
-
1
votes1
answer448
viewsHow to filter selected fields through Spring JPA using JPQL?
I would like to know how to proceed to filter selected fields using JPQL within the JPA/Hibernate implementation? The following scenario will be presented to facilitate understanding, following…
-
1
votes2
answers354
views(Query SQL) Limit the number of rows in a select with Inner Join and Where in
I have 3 tables, products, Category, product_categories, this last one was created pq the product and category relation is n to n. I have a select that returns me all products of all categories, but…
-
1
votes1
answer51
viewsQuery problem to filter different fields in the same SQL table
I have a table with GSUITE usage logs and I would like to filter some metrics one of them is the one that follows and that I am having problems to accomplish. (I’m a beginner in SQL) I am looking…
-
1
votes1
answer104
viewsSQL and R - Download data from a table with space in names and integer filter
I have a database in Postgresql and would like to download a table, but with some filters. The column 'CNAE 2.0 Class' is an integer. library(RPostgreSQL) PIA_Estab <- dbGetQuery(con," SELECT *…
-
1
votes1
answer49
viewsHow to write all columns of an SQL table + php
Good afternoon, I’m having a doubt, I wanted to create an echo that showed all columns with a select, my code is as follows <?php $db = 'localhost:F:\Dados\TGA.FDB'; $username = 'SYSDBA';…
-
1
votes2
answers76
viewsDisplay values in one table but not in the other
Good morning. I’m new to Database and SQL, and I have a question in a college exercise. The objective of the exercise is: I was able to do the part of presenting the number, description of the…
-
1
votes0
answers125
viewsUnion All for Entity framework using Lambda
I’m having problems in a query using lambda and Entity Framework in C#. When transforming a simple sql query into lambda works perfectly, as example below. SQL query public DataSet ListarRecebidos()…
-
1
votes2
answers59
viewsAverage between select results
I need to calculate the average repair time for each application. Knowing that I have in hand the repair code, application code and time for each repair, what would be the best way to perform this…
-
1
votes0
answers41
viewsButton to insert entries into the BD
I am conducting a project for my PEF that consists of creating a Company Database. However, I decided to put a button to add records and when I click to add, the following error appears: Failed to…
-
1
votes0
answers82
viewsExport image saved as Varbinary in different formats
I have some images in the SQL Server 2017 database that were recorded as varbinary. I already have a script that exports as . jpg, but I found that some images are actually . png or . bmp. Is there…
-
1
votes2
answers79
viewsMake two updates at once
I have a table with some records, I want to change two rows of this table at the same time I’m currently doing this: include("conexao.php"); $tabela1 = "endereco"; $endereco_id= "75";…
-
1
votes0
answers119
viewsUPDATE command on a JSON
Good afternoon, everyone, I’m trying to update a column of my table, but this column stores a JSON Object, only that for this I need to make a where with a JSON also. This one is how the data is…
-
1
votes1
answer57
viewsProblems with displaying data from an array
I’m new to stackoverflow, but that I use the platform to cease my direct doubts, had never made an account. Anyway, I have an atypical problem with a PHP code. I’m making a query to the database…
-
1
votes0
answers47
viewsOpenrowset error
good afternoon! I’m having trouble running an Openrowset: use Planejamento_QA go select * from openrowset('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=C:\Import_SQL\KE24.xlsx', 'KE24$'); go…
-
1
votes1
answer148
viewsIs there a performance problem in using many foreign keys (FK)? If so, is it bad to have foreign attributes without being FK?
To clarify how much can be "many foreign keys", I will explain the context: In a system, I want to store by whom a certain record has been edited ( updatedBy) or raised (createdBy). This can happen…
-
1
votes0
answers94
viewsSQL - I need to return months with zero values, even if it doesn’t work
I need to return the lines of a query, even if it has no value. This table has more status and needs to return all status with the respective months and year chosen, but with the amount zeroed.…
-
1
votes1
answer168
viewsError adding foreign key, how to proceed?
I am trying to reference the column id of a table in another table in my database, but I am told an error that is not very specific. The engine being used is Innodb and the database is in Mysql. It…
-
1
votes1
answer229
viewsSELECT with two Foreign key, return the two tables even looking for only one of the keys
I have a table that has two FK to reference the same table. By selecting all elements that have one of the two FK, using the query: SELECT "Proposta".id, "Proposta".id_segurado,…
-
1
votes1
answer48
viewsSELECT displaying the same field several times from a calculation
I started studying databases, I am using Postgres and I came across the following need, I have field "packages" in one in the table "flow", where I need to separate the packages by quantity of…
-
1
votes2
answers121
viewsSQL Update from another tab
Hello, I’m trying to update the product table using the average unit values of one year in the document table (where the notes enter) and the q instruction I’m using returns with error: UPDATE…
-
1
votes2
answers144
viewsCASE WHEN in Where clause and with THEN with more than 1 return value
Hello. I have an application for assembly of queries, in which I pass the parameters in the clause "Where". Only I came across a situation where I need to use CASE and in the THEN clause a range of…
-
1
votes1
answer66
viewsDoubt select with Where in SQL Server!
Hello! I have table relations up. I need to develop a return select: Cars, from the same manufacturer and model, which are put up for sale by more than one dealer. I arrived at the following code:…
-
1
votes0
answers84
viewsMultiple Joins to add different values of the same column
I’m having problems in a query (Firebird) with several Selects for the same Stored Procedure (SP_PRODUTO_MOVIMENTO), with practically the same parameters, differing only in the values of a column…
-
1
votes1
answer43
viewsMysql - A single entity (N:N)
Good morning guys. I’m new to database and I’m trying to understand some concepts: A single entity (N:N) A company works with projects in a horizontal way, where the person N in a project can be the…
-
1
votes1
answer32
viewsAdding 2 rows of fields in a Database using C# (MVC)
I am doing an Actionresult within a control to effect some purchase data. The idea is to buy and sell products (in this case Coins),negativando a Quantidade and positive Valor in case of sale and…
-
1
votes0
answers201
viewsEXCEL - VBA - SQL - Doubt in the query using CAST
Hello, First I apologize to ADM if there is any error in formatting the question, I am novice here rsrs. I have a question in the QUERY query using MAX and CAST Goal: Return the highest value in the…
-
1
votes0
answers25
viewsCSV file does not record all data in the database
Good evening, in my code when I send the CSV file It records only the last line of the file, when I use TRUNCATE TABLE. Without the truncate saves all lines, but the goal is to update the data by…
-
1
votes2
answers36
viewsConsult related data without repetition
I need to list all data in the CONTRACT table, but only when in the COMMITMENT table blocker = 1: CONTRATO COMPROMISSO codigos codgerado blocker 3315 1102 2 3317 1105 1 3318 1108 1 3320 3315 2 7726…
-
1
votes2
answers106
viewsSQL search between two tables with duplicate result
I have a View and a table. A View V_CUSTOMER with customer data, but does not have the same CPF/CNPJ as in the view, which is identified by the field V_CUSTOMER.CUSTOMER_ID that makes the…
-
1
votes1
answer35
viewsReturn value that is not in the other table
I have a query that returns purchase requests on a date, the requests are three, the 1594, 1595 and 1596.. These solitaires have shopping order referring to them that are in another table and that I…
-
1
votes1
answer84
viewsSeparate Columns in SQL Row Numbers
to with a problem for SQL Server. I have an event and value table and I make a Join with another table that has several columns, the amount can be marked as 1 for active and 0 inactive. As you can…
-
1
votes1
answer148
viewsInner Join returning duplicate lines
I have a purchase order table, which relates to the products table, The purchase order table can own multiple products, this consultation returns me all the purchase order, which has more than one…
-
1
votes1
answer117
viewsHow to extract a word from a string (SQL Server)
I’m having a problem with my script. Context: I need to get information from a string that is in the nm_content column, but all the functions I try are not working. I tried to do it separately and…
-
1
votes0
answers77
viewsUsing pivot, in this query with dynamic columns
I have the query below where I display products, ordered by the product code, the date of movement of the product is from the latest to the oldest, but as I wanted only the last 5 dates of a defined…
-
1
votes0
answers46
viewsReduce and simplify redundant sql (mysql) query for financial reporting (account hierarchy)
I have basic knowledge of database and Mysql, I wonder if someone could help me decrease the 'size' of a query and its redundancy (facilitating future maintenance). This is a financial report with a…
-
1
votes1
answer54
viewsSQL - Group information and Do not repeat
I’m doing an SQL where I need to show the purchase orders. However a purchase order, can have several quotations and do not want to keep repeating the quotations, I want to bring me the quotation…
-
1
votes1
answer112
viewsSELECT in two different tables with variables of the same name
I have the following consultation to be made: "SELECT DISTINCT andamento_processual.licenciamento_cod, andamento_processual.inter_simplificada_cod, andamento_processual.inter_pretendida_cod,…
-
1
votes2
answers74
viewsData Conversion in SQL server 2008
Hello! I need to do a data conversion in SQL Server 2008 from the "data field". Could someone tell me how this can be done? I tried so: select distinct c.Empresa, p.Nome,…
-
1
votes1
answer115
viewsIt is recommended to use the JSON type in the columns in the table below
I am learning relational databases, so I decided to create a school administration system, I made a table only to keep all the student’s school history (all the newsletters with other information).…
-
1
votes1
answer43
viewsSearch Word Combination in SQL (Redshift)
Dear friends, good afternoon. I have a table that stores the texts of messages exchanged by email and I need to identify the emails that comes with a set of words, for example: For any message that…
sqlasked 4 years, 1 month ago Augusto Schultz 23 -
1
votes1
answer39
viewsCatch the lowest and highest value of a category with the count and ID
I need some help to make a SELECT that returns me the highest and lowest value of a category with its respective IDs and the amount of each category. The algorithm is complex, because it needs to…
-
1
votes0
answers31
viewsSelect with 2 Inner Join returns no result
I have a relational database that has 3 tables: tb_functionaries, tb_licencas and tb_tipo_licencas, each with their respective primary keys. The tb_licencas table, however, has the keys of the other…
-
1
votes1
answer31
viewsDoubt about SQL
Good afternoon guys, I am learning SQL and I have to do an exercise that is: Select the first and last names of employees and consultants working in the "Financial" department. Turns out I’m trying…
-
1
votes0
answers118
viewsI cannot install Mysql, proble with MYSQL CONNECTOR NET 8.0.17
I had mysql on my computer working perfectly a while ago on version 8.0.17, I did the uninstallation months ago and today I had to install again, the latest version is on 8.0.22, when I tried to…
-
1
votes0
answers24
viewsDemand Forecast Monte Carlo Method
Good personal evening, I am developing a select in order to simulate a demand forecast in my company, I am using the Monte Carlo method, which uses a function to generate random values within the…
-
1
votes1
answer76
viewsHow to add SQL query result with more than 1 product multiplying by quantity of inputs. insert result in another table?
I need to perform a product SQL query that kit form, example: A product that has as sales value the sum of the product of its inputs made the query but is not adding the result. Select…
sqlasked 4 years ago Ivan Aguiar 11 -
1
votes1
answer21
viewsSelect a value depending on the chosen footage
I need to return the value of a product according to the chosen footage, this value is saved in a table this way de_mt | ate_mt | valor_mt -------------------------- 1 | 5 | 15.00 6 | 8 | 16.00 9 |…
-
1
votes0
answers42
viewsSql - How to make a name or surname unique
Guys, the following is a table called sqlite, and I want the following I don’t want data to repeat, but if someone with a name and surname is registered, I want a person with the same name to be…