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
answer33
viewssearch is not returning the php, mysql data
I am making a search page so that when I do the search is not returning the data could help me? what I’m missing? <?php require_once('Connections/conn2.php'); ?> <?php $tipo_prod =…
-
1
votes1
answer127
viewsSelect no Laravel is returning the column name (Eloquent)
I’m having trouble returning only the value of select in the case is the name ,but it is returning as if it were string and this with column name. Controller public function…
-
1
votes1
answer39
viewsReport with date_trunc including zeroed values
I’m doing a consultation in postgres, but it only brings the results where the inspection body is not reset, I needed this query to bring all the results from 8 to 18, including zeroes: AS YOU…
-
1
votes1
answer161
viewsColumn splitting error with SQL Subquery
I am using postgresql I have a query that when I run a division between the columns (soma_neighborhood / Soma_city) it always returns 1, should return the value described in the field and not the…
-
1
votes2
answers97
viewsSoftware with local and remote BD recording
I have a question about the possibility of doing a type of program and what means to use. Just for the record, I’m not asking for "how to do the programming," but an opinion from more experienced…
-
1
votes5
answers578
viewsHow to validate when Resultset does not find any value?
I’m trying to build a Java function pesquisarCliente where it must be consulted in the Database whether it exists or not. If there is more than one result you should return all records, if you do…
-
1
votes1
answer522
viewsStored Procedure With Select SQL SERVER
Good evening, I’m trying to create a stored Procedure that will fetch one of the data in a select, the reason is because I have a table of items, and I need to enter all the codes of the items in…
-
1
votes2
answers7751
viewsORA-06502 - string buffer too small numerical or value - Long Field
Good morning, I’m performing a query to query data in a Long-type field. I created the following Function to bring the data: CREATE OR REPLACE FUNCTION "SEARCH_LONG" (r rowid) return varchar2 is…
-
1
votes1
answer34
viewsSQL Insert when Inserted but Skip Duplicate
USE [RF_World] GO SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER dbo.UserStatusUpdater ON dbo.tbl_base AFTER INSERT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from…
-
1
votes0
answers72
viewsResult + Grouping Mysql result
I have a tremendous doubt in mounting this query that I am attaching, I have a table and cross with another to know the state where had more sales, where the result is grouped and shows me the total…
-
1
votes2
answers36
viewsSelect separate data from two tables excluding repeated ones
How could I select in two tables bringing the column data SKU of both tables even if the data of one table does not exist in the other table, also need to delete the repeated data. These are the…
sqlasked 5 years, 3 months ago Hugo Rutemberg 307 -
1
votes2
answers911
viewsFields with the same name in different tables
Fields with the same name in different tables may cause conflict at the time of normalizar or make some inner join? Examples Supplier Table Field: name Field: surname Field: email Product Table…
-
1
votes2
answers72
viewsCount values in multiple related tables
I have 4 tables tbl_Distrito, tbl_Unidade, tbl_Servidor, tbl_Processo. tbl_Distrito: Cod_Distrito, Nome_Distrito tbl_Unidade: Cod_Unidade, Nome_Unidade, Cod_Distrito tbl_Servidor: Cod_Unidade…
-
1
votes1
answer174
viewsadd and split results in the same query by taking the result of the first sum
I need two information I make the first sum SELECT FORMAT(ROUND(SUM(CASE WHEN MONTH(periodo) IN (12) AND classificacao = '3.6' THEN IFNULL(debito-credito,NULL) ELSE 0 END)) ,2) AS custo_1, Right…
-
1
votes1
answer190
viewsHibernate can’t find an existing column, ERRORCODE=-4460
I am having a difficulty in my system where SQL with Hibernate can not find a specific column by Java, the same query returns the right result when rotated by SQL. IDE used is Netbeans. The query is…
-
1
votes1
answer149
viewsForeignkey error with Sqlalchemy
Basically what I want is for him to register in Transaction() the Account he sends and the Account he receives the amount. However I am not able to link the two Foreign key with the accounts I am…
-
1
votes3
answers61
viewsQuery SQL Doubt - Query using two tables
I’m having doubts about how to query. The problem is the following: I have two tables similar to the ones described below (I don’t have exactly how they were, but are next to the representation…
-
1
votes1
answer39
viewsWhy Between doesn’t bring the right answer
I have a specific table with the data that I do the search (sales_flat_order) where column status has among other values ('entregue', 'entregue_pd', 'entregue_pd_pago', 'avaliacao_solicitado',…
-
1
votes1
answer490
viewsConvert Varchar to Int
I need to perform a sub query in Query but the data types of the columns are different. I am using the structure below but it is in error : SELECT MIN(POPULACAO), nome_mun from cidades select…
-
1
votes1
answer121
viewsSet existing value in combo box C#
I am passing a completed DTO object to an editing form, through the event click on a Change button. In this edition form, I want all fields to be filled out as soon as it is opened, but the fields…
-
1
votes2
answers1604
viewsConversion of a data type scan into a data type datetime resulted in a value outside the yyyy-mm-dd range
I have a column called produtodata which has the following datetime format: 1753-01-01 00:00:00.000 I need to filter the records that are between the date '2019-06-26 00:00:00.000' until today. I…
-
1
votes1
answer247
viewsHow do I put an Alert with IF in Javascript using Values List
I’m setting up a javascript function that makes a list of values control SELECT in my SQL. Because the List of Both are giants. So maybe from the guy clicking directly to show everything from the…
-
1
votes1
answer38
viewsHow to know which users have a photo in a folder via OPENROWSET?
I have a system where photos are stored in briefcase and not in the database. To save the photo file, the system uses the following standardization: Username: Otávio Augusto | Primary Key: 12345…
-
1
votes0
answers208
viewsCount number of occurrences in Postgresql
I have a database where the values are organized more or less as follows: id | produto | data com registro de venda ---------------------------------------------- 1 | Prod1 | 17/09/2019 2 | Prod1 |…
-
1
votes0
answers95
viewsError while creating tables in mysql
I am trying to create these tables by mysql but it is giving error. I created the relationship between the tables in Mysql Workbench. Can someone give me a hand? ERROR: Static analysis: 1 errors…
-
1
votes1
answer59
viewsDatatype Conversion Query - Varchar to Float
When performing a query, I need a column of a given table to convert your Datatype for FLOAT. COLUMN CONFIGURATION Name: 16_remuneracao_sem_13 Datatype: VARCHAR(15) PERFORMING STANDARD CONSULTATION…
-
1
votes1
answer91
viewsHow to add values of others in a new column? Ora-00904
I created the columns A, B, C e D. When trying an E Column, which is the sum of the previous ones gives this error ORA-00904, have tried some examples I found in pequisa, gives in the same.. SELECT…
-
1
votes1
answer1099
viewsOracle - WHERE WITH SYSDATE
In the first select the BALANCE is coming zeroed, in the second I replace the sysdate by which would be the date it brings the correct value what must be the problem in sysdate+4 in Where? SELECT…
-
1
votes3
answers72
viewsmysql repeated names by select
I am trying to show a table where only the name of the author appears once in which his book is in stock=0, however I am getting the name of all authors in duplicate, even when the author has no…
-
1
votes1
answer49
viewsDoubt syntax: How to find the minimum and maximum value of a field in Line with Where
I need to create a function in linq return me the minimum and maximum values of a field in a list. I was able to perform an SQL query in this way, but I need this in the syntax in linq. SELECT…
-
1
votes1
answer2432
viewsSQL - SELECT DISTINCT in only one field
So, I’m doing a search in which returns the non-repeating geometries (which has as layer name Access and Middle): SELECT DISTINCT geo_geometria FROM geral_elemento_cartografico WHERE ds_camada LIKE…
-
1
votes1
answer70
viewsHow to show certain amounts of lines?
I have a query that takes the highest sales values of a given product per year . The query follows this structure : select ano , descricao, sum(valor) as valor from produtos group by descricao, ano…
-
1
votes1
answer1161
viewsPercent calculation in Oracle SQL
I’m mounting a query where I need the percentage of category for each cargo. If I filter for only one load, the query returns correctly. But if I put more than one (a period, for example) the…
-
1
votes1
answer474
viewsRemove with regex everything after two points in the SQL query
GOAL I want to remove with regex in SQL query everything after two points, can anyone help me mount this query? I made several attempts, but without success. Normal query Remove with Regex Desired…
-
1
votes0
answers56
viewsSort mysql query correctly
I have a query to fetch some values, however the value does not return me correctly. In the example below you will notice that user 1 is below user 2. In this case the order should be in this…
-
1
votes1
answer42
viewsComposite foreign key - ERROR 1215 (HY000): Cannot add Foreign key Constraint
I during the creation of these 3 tables came across the error: "ERROR 1215 (HY000): Cannot add Foreign key Constraint" The only conclusion I could come to is that the problem lies with the field…
-
1
votes0
answers37
viewsGroup a date field in months
Good afternoon, could someone help me? How can I put this query to display from January to December correctly? SELECT EMPRESA,ATIVIDADE,DATA,STATUS FROM tbl_atividades WHERE YEAR(dt_vencimento) =…
-
1
votes0
answers95
viewsSum the total values entered in a table - PHP
I would like to add up the total values entered in the database and presented in a table. Add up all values including new releases. Stages: 1- Register value and send to the Database (registration…
-
1
votes1
answer57
viewsError executing a subquery in sql server
I am trying to return values where the date is between two fields of my page this field and max(field) This is the consultation: SELECT COD_SECAO , SECAO , CHAPA , NOME , DTNASCIMENTO , DATAADMISSAO…
-
1
votes0
answers60
viewsAdding Records with Specific Data
Well, I’m currently working on a project that we use Clientdataset’s to communicate with the database. My problem is Next, I have a Receiving Report in the Export Sector, in which there are several…
-
1
votes1
answer111
viewsC# - LINQ ERROR "The data type text and varchar are incompatible with Equal Operator"
I find the following error when trying to update a table: the data type text and varchar are incompatible with Equal Operator. I have done several searches and most indicate the same solution:…
-
1
votes1
answer82
viewsError while trying to run an Update with Parameter in SQL
I’m having a little problem that’s being a headache. I want to update with a SET, where it involves two parameters concatenated. Following update: update tabela_usin usin set usin.peca = &P1 ||…
-
1
votes2
answers420
viewsThe Datediff function resulted in an Sql Server overflow
I have the following appointment: SELECT ISNULL(MAX(CONVERT(TIME(0), DATEADD(SECOND, DATEDIFF(SS, [INICOLIGACAO],[FINALLIGACAO]), 0))),'') AS [DURACAO_CHAMADA] WHERE CONVERT(DATE,[DIA]) =…
-
1
votes1
answer64
viewsSubquery with the records of a column
I have the following problem... I need to extract the information from a table where it has the following structure: tabela: PROCESSO_VALOR_TIPO Coluna : field_model_ids Dados :…
-
1
votes1
answer129
viewsHow to use new in SQL?
My goal is: so insert an element into banco1.Clientes the same is inserted in banco2.Clientes via a Trigger. If this element is already in the bank, there should be an update. But I cannot use the…
-
1
votes1
answer41
viewsConcatenate with specific format
I need to concatenate two columns, a year and a month, but still keep a number of characters limited to six. And when the month is less than 10 the output brings the concatenation but only with 5…
-
1
votes1
answer625
viewsHow to use CASE in a Where clause
Hello, I have the following script situation: SELECT * FROM Formulario WHERE DataInclusao = '2019-10-28 08:19:54.000' AND chave = 'XXXXXXX' AND Id = 2 This table has a column called Productoid, in…
-
1
votes1
answer139
viewsHow to take the record value according to its position number in SQL SERVER
I’m randomly populating the tables of a database I created and I’m trying to populate a table that has foreign keys. My idea is to create a while loop and get the ID (the values are random) of the…
-
1
votes1
answer65
viewsCount without returning 0 in Presto
My query is this: with dates as ( SELECT CAST(date_column AS DATE) DAY FROM ( VALUES ( SEQUENCE(cast('2019-10-29' AS date), current_date, INTERVAL '1' DAY) ) ) AS t1(date_array) CROSS JOIN…
sqlasked 4 years, 11 months ago Camila Lira Alves 11 -
1
votes1
answer31
viewsError when performing query with Linq Groupby in C#
I need to select the Groups previously registered, bringing data not repeated. However, an error is returned when performing the query in the table Point of Attendance, where the countryside Group…