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
answer56
viewsWhat are the differences when including values (coming from a form for example), in a query mounted in PHP and executed in MYSQL, among the forms below?
I have studied and seen that there are different ways of treating data before inserting them into a query which is executed in the database. I have some questions about security and the issue of…
-
0
votes1
answer61
viewsMysql relationship between two tables
Good morning, for a work record I was given the following exercise: Imagine the following scenario. It is intended to create a database that supports the control of stocks. Each product belongs to a…
-
0
votes4
answers114
viewsDoubt QUERY SQL construction
I have two TB1 and TB2 tables with equal fields in order to compare the records. The logic is: Query the records contained in TB1, but not contained TB2, considering 3 fields: code, date and value.…
-
0
votes1
answer76
viewsSQL - Perform the removal of two rows in separate tables connected with Foreign Key
Good afternoon, I have a little doubt on a personal project of mine. I own the tables request and itens_request which are connected by foreign key. As an example to simplify my situation: Requested…
-
0
votes1
answer231
viewsMerge 3 selects into a single select
I’m using the Warehouse Snowflake, I have to make some selects 1° Select select WAREHOUSE_NAME, TOTAL_ELAPSED_TIME, QUERY_TEXT, START_TIME from SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY where…
sqlasked 4 years, 11 months ago Patrik Roger 63 -
0
votes2
answers53
viewsAggregation error only in postgresql 9.4
I am having the following error when using the postgresql database in production (version 9.46), in development the error does not appear (9.6). PG::Groupingerror: ERROR: column "sectors.name"…
-
0
votes3
answers101
viewsReturn value corresponding to date
I have a table with values and dates referring to the cost of a vehicle. However the table is filled in as follows: data_saida | custo_saida ------------------------- 2019-11-17 | 25 2019-11-18 | 20…
-
0
votes2
answers55
viewsHow to make a codition inside a NOT IN on Sqlserver
Suppose I have the following data, license plates, category, and situation: 1- 1 - Encerrado 2- 10 - Concluído 3- 11 - Pendente 5 - 2 - Encerrado 6 - 1 - Pendente 9- 10- Encerrado And I want to do a…
-
0
votes2
answers322
viewsInsert a Count(*) value into a variable in Postgresql
I am migrating from Mysql to Postgresql and trying to create the following Trigger: CREATE OR REPLACE FUNCTION verificaReservaQuarto() RETURNS trigger AS $$ begin declare ocupado int; declare…
-
0
votes2
answers169
viewsHow to make a group by Select is done to more than one table
SELECT tblOrgao.eleicao_id as IdEleicao, tblCargo.orgao_id as IdOrgao, tblOrgao.orgao as Orgao, tblCargo.id as IdCargo, tblCargo.cargo as Cargo, tblLista.lista as NomeLista,…
sqlasked 4 years, 11 months ago Amadeu Antunes 3,331 -
0
votes1
answer268
viewsPHP error connecting database to server
I’m having a doubt when I change my credentials of the database at localhost for the credentials of the database at sql server give me this php error Warning: mysqli::__construct():…
-
0
votes1
answer69
viewsSequence in Oracle SQL with strange behavior
I created an Oracle database with the following script: CREATE SEQUENCE pcn_integra_ser_nfe INCREMENT BY 1 START WITH 1 MINVALUE 1 MAXVALUE 9999999 NOCYCLE NOORDER CACHE 20 It is used in only one…
-
0
votes1
answer424
viewsConvert Varchar in Int or Int in Varchar (SQL Procedure)
in Procedure there are two fields (Cod_manufacturer(VARCHAR) and Codigo_manufacturer(INT)), a Varchar and an Int, when I do a LEFT JOIN to cross the tables, it gives me a conversion error, I tried…
-
0
votes1
answer342
viewsRead data from an Excel cell to search via SQL
I need to execute an SQL that brings me a result of only one cell, but, I need to capture information of two. I will enter with start date and end date, my result will be a calculated value in that…
-
0
votes2
answers246
viewsQuery Mysql to count contracts with INNER JOIN
Hello, relating the following tables: Contract table tb_contrato id credor_id num_contrato Invoice Table tb_fatura id contrato_id num_fatura dt_vencimento valor Parameters credor = 1 valor inicial =…
-
0
votes0
answers61
viewsROLLUP and HAVING in the same consultation
The query below returns the sum of 24 accounts, using the ROLLUP and without the clause HAVING, so far so good, but when I use the clause HAVING shortly after the ROLLUP should return me the sum of…
-
0
votes0
answers48
viewsDoubt for database structuring - SQL Server
Good night! I would like to ask for help to have some ideas, I will explain more or less what I would like: Let’s say I have two databases, one to serve as Central (receives information from various…
-
0
votes1
answer86
views -
0
votes0
answers166
viewsError in performing the Insert in oracle
I’m having problems to perform the Insert in a table called accounts, however I have relationship with the company table. In the company table I have the following fields: Id_empresa | Nome_Empresa…
-
0
votes1
answer786
viewsHow to join these two selects of the same table in SQL server?
Next, I need the amount per month of each customer who entered the year managed to do this, however I want q be shown in only 1 result. How do I join the two SELECTS? In order that it is added to…
-
0
votes1
answer105
viewsSQL - UPDATE with value from SELECT
Dear, I have two tables (A and B), in which B has a foreign key of A. Example: A(id, campo1, campo2) B(id, idA, campo3, campo4) I need to count the amount of B.idA and thereby define a true or false…
-
0
votes0
answers47
viewsRestrict way to insert into SQL tables
Hello, I have a database in which I save some information of the establishment in a table and then the information of the same address, in another table. I wonder if there’s any way I can narrow it…
-
0
votes2
answers182
viewsSELECT in N:N relationship without using INNER JOIN
I need an SQL equivalent to a SELECT using INNER JOIN as I am using Sphinxsearch and read that it does not support INNER JOIN. I know you can do it using Sub-Query but I can’t remember how you do…
-
0
votes0
answers256
viewsSQL Error [42601]: ERROR: syntax error on or near ":" Position: 683
I am trying to make a query with CONCAT, Seto the values I wish only that returns syntax error SQL Error [42601]: ERRO: erro de sintaxe em ou próximo a ":" Position: 683 select processador.cd_code,…
-
0
votes0
answers163
viewsQuery JPA using Paging is taking longer as the page number increases, and generating timeout
I’m running a query with JPA on a cloud server of the google app engine, this query should bring me millions of records, and so I’m using Pageable on it, to avoid bank timeout, the problem is that…
-
0
votes1
answer78
viewsSQL gets Double with "Comma" tab instead of "Dot"
I am developing an ASP.NET application where I need to take a DOBULE typed by the user and pass to the bank. However there is a divergence of information, the DOUBLE of my bank receives separator…
-
0
votes2
answers103
viewsError giving python Mysql Insert
I have the table in my bank: create table tweets( ID_Tweet int not null auto_increment, ID_Candidato int not null, Conteudo_Tweet varchar(470) not null, constraint PK_tweets_ID primary key…
-
0
votes1
answer60
viewsTwo WHERE with two independent conditionals
Fala Pessoal, I am mounting a query with the objective of bringing 2 columns that do the same query but with 2 different conditions. ex: SELECT COUNT(MAX(l.created_at))as last_login_x1,…
-
0
votes1
answer57
viewsError while UPDATING Image URL in Database
When running the PHP code I get the following error: Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or Identifier (T_STRING) or variable (T_VARIABLE) or number…
-
0
votes1
answer557
viewsCase in Where for query filter
I have this select below, but when date is true, he needs to bring all the records where the field OrdemServicos.DataConclusao is different from null, and when it is false needs to bring everyone…
-
0
votes1
answer182
views'System.Data.Sqlclient.Sqlconnection' does not contain a Definition for 'Query'
I wrote a C# method to make a "switch" between different database types in my application. Where the problem is that each database type makes use of a different library (SQL => Sqlconnection and…
-
0
votes1
answer58
viewsString missing characters(from php database)
What is happening here is that a string (varchar), coming from a database query, is missing characters when I go to php , php read until a certain part later stops. When I do a query Using SQL…
-
0
votes1
answer40
views -
0
votes1
answer16
viewsReporting Services does not bring line with zeroed values
I am making a report of the students' status by course modality, where I need to display a matrix, even if all values are zeroed. By filtering a certain course, which does not contain the "Distance"…
-
0
votes1
answer260
viewsMultiply two columns in a select With Groupby
How Can I Do This Multiplication? the table looks like this: What has to be done is to group disciplines 11 and 13, count how many 'sit' F and Null have and multiply by 'qntd_aula'... I managed to…
-
0
votes1
answer270
viewsHow to consume a JSON on a localhost webservice with android studio
Good night, so I don’t know if my code is correct so I’m not sure why it doesn’t work, follow my code in android studio package com.example.aplicativoderestaurante; import…
-
0
votes1
answer669
viewsAdd values from previous line to next
I wonder if there is a way to add up the values of a line with its previous. Ex: In select below, the result I’m getting is not doing the accumulated **SELECT DATMOV, VLRMOV, DEBCRE, (CASE WHEN…
sqlasked 4 years, 9 months ago Marcos Vinicius Sousa Damascen 1 -
0
votes1
answer28
viewshow to use the SELECT statement to be inserted in a column in the same table?
SELECT Names,SUBSTRING(Names,10,50) AS Alias FROM NameToSplit; Here I do not want to put the Aliases, but INSERT in the column Alias this Select statement. then I need to take this column Alias and…
-
0
votes0
answers65
viewsProblems with Table Modeling with Two Foreign Keys
I need to finish a modeling of a database and I’m at an impasse. Simply put, I have 3 tables as follows: PROMISSORY NOTES CREATE TABLE IF NOT EXISTS `picinin`.`promissorias` ( `id_promissoria` INT…
-
0
votes1
answer79
viewsINSERT with SELECT in mysql
I just created a field on my table reporterio_psi called convenio. I have a table called patients, which also has a field called convenio, where they have data in this field. In these two tables,…
-
0
votes1
answer327
viewsCheck if table exists before entering value in the Sqflite -- Flutter database
I am developing an app, my problem is that with app updates I can use other tables that do not yet exist in the existing database. The solution that came to mind was always before entering a value…
-
0
votes2
answers44
viewsDoubt group by oracle
I want to do a group by between two tables by doing an Inner Join. The employee table and the table employed at the post. I want it to return to the most recent entry into a post of a given…
-
0
votes0
answers71
viewsRead an image in SQL Server for a picturebox in C#
I have Bytearrays of images in a database on Mysql Server and I intend to read them and after that convert Bytearray to an image that can be arranged in a picturebox. I have tried using other…
-
0
votes2
answers74
viewsSQL EMAIL PATCH
Well I have several emails with problems at the end ex: hotmal without the . com @gmail without the . com, etc. What I am trying to do in oracle database, I look for gmail.com with the function…
-
0
votes0
answers51
viewsCondition for oracle sql query
I have a user information search service by its registration in an x table. The registration I receive as parameter for the search comes complete (Ex: T111111), while in the bank it is registered…
-
0
votes1
answer215
viewsHow to recur SQL server using WITH to return all children
I am trying to make a recursive in a single table called local where there is a localSuperior ID, referencing the same table. If I have my biggest place with ID 1664, when making the recursive, it…
-
0
votes1
answer18
viewsError with With SQL (Presto,Athena)
all right? I’m having a problem with the With, I am trying to create a table grouped with a column not grouped. In case I’m trying to assemble a table with the total transacted of each group + total…
-
0
votes2
answers206
views1 select with two columns
Well, I’m performing a select between two dates that returns me two values. Quantity of purchases paid in CASH. Amount of purchases paid by credit card. I’m doing it this way, SELECT…
-
0
votes1
answer28
viewsDoubt in the use of Dateformat in linked server (Linked)
I have the following situation. Executing that script: SELECT CONVERT(DATETIME, CONVERT(VARCHAR, 12) + '/' + CONVERT(VARCHAR, 31) + '/' + CONVERT(VARCHAR, 1900) + ' ' + CONVERT(VARCHAR, 0) + ':' +…
-
0
votes1
answer528
viewsMysql - Cannot add or update a Child Row: a Foreign key Constraint fails (`areas_knowledge`. `sub_areas`,
Hello, I am doing a job that consists in developing a system to manage projects and etc. In this system I need to have a table with the knowledge areas of cnpq. I’m taking the Grande Areas, Areas,…