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
votes1
answer61
viewsSearch json tags with REGEXP ignoring accents
How can I ignore the accents with regexp? with LIKE was working, however I was having trouble with posts whose number of tags was large. SELECT id, JSON_EXTRACT(quiz_json, '$.tags') from…
-
0
votes3
answers255
viewsSQL bring result with repeated column numbers all only the largest
Hello guys I’m trying to get a data but I’m not able to filter the way I need, example : select a.cod, a.nome, b.pedido, b.versao from cliente a inner join pedido b On a.cod= b.cod order by b.pedido…
-
0
votes1
answer116
viewssql server Developer 2017 installation error
When trying to install sql server Developer 2017 I get the following error message: "Opa... there was an error when checking the sql server configuration rules". Windows 10 Pro (but not enabled)…
-
0
votes2
answers467
viewsHow to check query with empty return?
I have a query with many columns and when I return empty I want it to show 1. However, I cannot do the check due to the many columns and the GROUP BY. A simple example follows below : SELECT ISNULL(…
-
0
votes0
answers50
viewsHow to use Count correctly
I used this query to find the Js that do not relate: SELECT *FROM D_WRKDB.TB_RDMP_CTRLM_JOB CTJ LEFT JOIN D_WRKDB.TB_RDMP_CTRLMJOB_HAS_WORKFLOW CTW ON CTW.ID_CTRLM_JOB = CTJ.ID_CTRLM_JOB WHERE…
sqlasked 5 years, 2 months ago Rafael Gonzales Da Silva 11 -
0
votes1
answer46
viewsDoubt how to recover data from another table with Postgres
I have two tables: Department with id and name Telephone contains id_department and extension I have already registered a department and some extensions where the id_departamento refers to the…
-
0
votes2
answers62
viewsOptimization in SQL
Is there any way to improve that stretch?
-
0
votes1
answer191
viewsExport from pandas to MS SQL using to_sql and sqlalchemy
My problem is with Float values example: df = pd.DataFrame([1.45]) conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params) engine = create_engine(conn_str) df.to_sql(name='teste',con=engine,…
-
0
votes1
answer55
viewsI’m having some problems with GROUP BY
I’m having trouble assembling a select with the GROUP BY. What I want to do is this: I have three tables: bicos idbico, idempresa, idbomba abastecimentos idabastec, idbico, idempresa, valorabastecim…
-
0
votes2
answers690
viewsSQL - group by, Count
Good afternoon, I currently have the following code and result. I would like instead of having this result, to have only one row for each type (column 1), this row being the one whose column 4 has…
-
0
votes1
answer1541
viewsTo assign the value 0 to a query by returning NULL SQL
Good afternoon, I have a question regarding the treatment of values in a query. The query below to the executed returns a null value NULL as I could assign the value 0 instead of NULL? select…
-
0
votes1
answer34
viewsError query update set
To $query1 and $query2 work, but the $query1a update is not setting, can anyone tell if it is syntax error? $conexao = mysqli_connect('localhost','rr','4ai','rr') or die('Erro ao conectar ao banco…
-
0
votes1
answer56
viewsSeparate string data from a table into other tables
Good morning, I have a table called TP_SAN_SRV, which is the table that has the blood type and blood factor, but I need to separate them in two, where the blood type and blood factor are separated.…
-
0
votes1
answer2559
viewsSet value for an oracle variable and use as parameter
What’s wrong when I try to set a value to an oracle11g variable and use it as parameter ? I found a post with the same doubt and adopted one of the solutions but the error continues: DECLARE ID…
-
0
votes1
answer26
viewsSql Exec Problemas
Well, I’m trying to execute the command below, but it’s always giving error, someone knows why? declare @maquinaCount varchar(max); declare @maquinaOnline varchar(max); select @maquinaCount =…
-
0
votes1
answer107
viewsMysql Process Error
I’m trying to create a procedure but I’m getting errors, after a few attempts, I managed to solve some problems, but I’m not getting more. When trying to create me generates error > ERROR 1064…
-
0
votes1
answer25
viewsSubselect Orderby first line
I’m doing the select below but in the last subselect (Mileage) I’m having problems with the ORDER BY "ORA-00907: Missing right parenthesis" error, if I remove the ORDER BY it works. SELECT /* DATE…
-
0
votes1
answer31
viewsHow to exclude a data from one or more tables
I have an id that appears in several tables but, I need to delete it in the main page and delete it in all other tables as well. ex : DELETE FROM admissao_dominio.*, admissao.*, bancarios.*,…
-
0
votes1
answer51
viewsHow do I add values from different tables?
I have two tables (Costs and Receipts) where I need to make one sum of the field containing values of each of them, after making a calculation (Balance) showing the balance of the Revenue - Costs =…
-
0
votes1
answer116
viewsDisplay a record by quantity and the most repeated value of a column
Hello, I have the following problem: I need to display the localities, the number of shipments of each one (ie how often the name of the locality appears in the column) and the most common disease…
-
0
votes3
answers399
viewsHow to select the last rows added in a mysql table
I have the following table sir_ter_conversa which is a conversation history. id|idterreno|idincorporadora|idusuario|msg|data 1 | 1 | 771 | 771 | a |2018-05-27 10:20:00 2 | 1 | 771 | 773 | b…
-
0
votes1
answer64
viewsHow to count how many records there are in a Onetomany relation?
I have two tables that are related in Onetomany format, example: I have a record of table A that relates to 1 or more records in table B. I’m trying to do a query that returns how many records in…
-
0
votes1
answer33
viewsSQL: JOIN and Count Repeated Number
I need to join Table Client along with the Table Request and would like to compare the Client id. the client ID of the Client table, Along with what’s inside the order table in case the column…
-
0
votes2
answers391
viewsBring the second and third line of a query
Oracle-SQL I have a chart that records the time records that each employee makes. The table contains the following information: (TABELA QUE ESTOU FAZENDO A CONSULTA) Contrato | Data | Hora 1 |…
-
0
votes2
answers95
viewsWoocommerce show products featured by sql category
would like this result to be just 1 with all formations separated by column and that it only appears if there is name = 'Resin' AND name = 'featured' otherwise do not list sql if I put WHERE b.name…
-
0
votes1
answer413
viewsC# CRUD - Insert Error (Cannot add or update a Child Row: a Foreign key Constraint fails...)
Good morning, I had managed to do everything right up to this error by inserting something into the database. localhost/phpmyadmin - xampp. It’s something with the id_user but I don’t know what it…
-
0
votes1
answer24
viewsHow to save data from a Carraydataprovider in the Database?
Hello, I have a Carraydataprovider and wanted to save your data in a table through a model, I have tried several ways and did not get result, which would be the best way to save it? My last attempt…
-
0
votes0
answers61
viewsSQL with SELECT and SUBSELECT to mount a chat
Hello guys from Stackoverflow, I’m mounting the SQL below to mount a chat service user, which brings the list of all active conversations, but I’m having a problem, my SQL is bringing the latest…
-
0
votes1
answer37
viewsFilter data that is not between dates
We are making a bucket rental system for our tcc, but on the sales screen we only need to appear the available buckets in the selected period. SELECT tabCacamba.CodCac, tabPrestadores.CodPre,…
-
0
votes1
answer23
viewsIs it possible to know the Column selected by GREATEST in Mysql?
Hypothetically, having 8 columns in an X table, 4 of these columns store an average: AVG(colunaN) And the other four store the amount of elements of that average COUNT(column) In a query I’m trying…
-
0
votes1
answer461
viewsDelete - Which is the fastest?
I need to delete from a large table some records. What is the best alternative: Use DELETE Tabela where id in (select id from @temporaria) or delete Tabela WHERE exists (select id from @temporaria…
-
0
votes2
answers119
viewsLIMIT IN A QUERY IN A FIELD
I have a table where there are two fields with possible values: yes-no. The select I’m doing is this: select nome, media, escola as 'Particular', bairro as 'COTA DE BAIRRO' from alunos where curso =…
-
0
votes0
answers39
viewsFunction in Oracle Sql
How do I perform these if Else in SQL create or replace function inss(x real) return number is begin if x <= 840.55 then return ((7.65/100) * x); else if (x >= 840.56) and (x <= 1050.00)…
-
0
votes1
answer247
viewsQuery Mysql with 3 tables
I have the following query that should bring the sum of views and last view (table sir_ter_relatorios_terrenos), sum of favourites (table sir_ter_favoritos) and the person’s name (table sir_users)…
-
0
votes1
answer61
viewsHow to improve this sql code?
I would like to improve this code so that it does not repeat the same code in both Ifs. I don’t feel like using procedures because I don’t see the need. DECLARE @Ordem VARCHAR (7), @Valor…
-
0
votes1
answer82
viewsselect return results without repeating reply
I have the following query SELECT (SUM(DISTINCT result)/COUNT(*))as total, uf FROM users WHERE result > 0 and result IS NOT NULL GROUP BY uf ORDER BY total DESC LIMIT 5 I want to select all 5…
-
0
votes2
answers81
viewsSum and total sql
Hello I have the following sql: `SELECT sum(value) the exits, (select sum(value) FROM entries WHERE id_type = 1 ) recipes FROM lancamentos WHERE id_type = 2 group by id_tipo ` It’s working ok, I…
sqlasked 4 years, 11 months ago Victor Maziero 41 -
0
votes1
answer18
viewsImport description from another table
Hello guys I have the following code: SELECT COUNT(*) AS categorias_total, v_lctos_despesa.id_categorias FROM 'v_lctos_despesa' INNER JOIN categorias ON (v_lctos_despesa.id_categorias =…
-
0
votes1
answer110
viewsquery the bank with ajax in beforeSend
How to make a bank consultation with ajax in the beforeSend? Example: var formData = new FormData(this); $.ajax({ url: "../_requeridos/cadastraPlano.php", type: 'POST', data: formData, beforeSend:…
-
0
votes1
answer830
viewsHow to make SQL query using like comparator and various values out of order
I looked for answers here in the community, but I couldn’t find anything specific. I have a page where I can search the name of previously registered clients in a Mysql database. Currently, I am…
-
0
votes1
answer145
viewsUnfold lines in a date range
I have a question regarding SQL SERVER and I needed your help. I have a Query that returns me a line with a number, Start_date and End_date. Consultation: select 123456 as Numero, a.Data_inicio,…
-
0
votes1
answer45
viewsINNER JOIN is not showing two rows in the table
I am trying to make a query in sql INNER JOIN two rows of my table does not appear. SELECT Rma.cod_rma,Rma.cliente_rma,Produto.Sku_prod,Produto.Nome_prod, Rma.Serial_rma FROM Rma INNER JOIN Produto…
sqlasked 4 years, 11 months ago user171227 11 -
0
votes2
answers66
viewsWhat’s wrong with this query?
Okay, I’m trying to select a database through ajax using jQuery. Below are excerpts of the code I’m using and more explanations: Ajax function function carregaRegistros(dia, mes, ano) { dia =…
-
0
votes1
answer45
views2 calls to the same table in Sqlite (output different than expected)
Given the following 2 tables: CREATE TABLE IF NOT EXISTS sugestoes ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, texto VARCHAR(250), autor VARCHAR(250), itens VARCHAR(250), pontos INTEGER );…
-
0
votes1
answer679
viewsHow to use Max() and Count() function together?
Talk personal! I am training a subselect with having using the MAX AND COUNT functions together, but Sqlserver is returning me an error called: "It is not possible to perform an aggregation function…
-
0
votes0
answers60
viewsHow to get next code from a table in pgsql?
In Mysql I use the syntax SHOW TABLE STATUS LIKE 'NOME_DATABELA' How I capture the report in Postgres?
-
0
votes1
answer338
viewsJoin with various conditions
I have two tables and need to unite them bringing the result through the following conditions: The Numero_tel_origem and Numero_tel_dest table 1, has to be the same Numero_tel_origem Numero_tel_dest…
-
0
votes0
answers422
viewsHow to align the Select result
I’m drawing up a report, where I take a person’s name, and what days they work. I was able to make that select, but I need it to stay that way: [JOÃO - SEG/QUART] [MARIA - TERÇ/QUINT] [JOSÉ -…
-
0
votes1
answer41
viewsError creating Trigger with more than one table
I’m having trouble creating a Trigger that modifies more than one table. DROP TRIGGER IF EXISTS vendedor_pago; DELIMITER $$ CREATE TRIGGER vendedor_pago AFTER UPDATE ON parcelas FOR EACH ROW BEGIN…
-
0
votes0
answers192
viewsQuestions about Picker in Xamarin.Forms
I am creating a mobile application where the user can register x ingredients and later can register products choosing which of the registered ingredients such product uses. In this perspective:…