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
answer85
viewsHow to query multiple select in only one sql line to get 7 daily result
SELECT count(*) as dias FROM users WHERE DATE(created_at) = CURRENT_DATE()-0 I have this sql line that sums all records made of the current day. But I want of the 7 days in a row would have like to…
-
0
votes1
answer56
viewsSQL Server: Access tables in [Cg]
I have a set of tables of "like" Cg in a database, but I can’t access it, it has two types of sets Cg and Dbo, i can access only the tables that are in dbo. Example: Tables inaccessible guy: Cg That…
-
0
votes2
answers90
viewssql filter in another table
Good morning, I have a problem where I have the following code working. select (sum((case when (lanc.id_tipo = 1 OR lanc.id_tipo = 5) then lanc.valor else 0 end)) + sum((case when (lanc.id_tipo = 2)…
-
0
votes1
answer68
viewsSQL ALTER TABLE
I need to make some changes in my bank, but before adding a new column I need to check if it already exists, if there is no create new column if there is no column then create Command found to check…
-
0
votes0
answers35
viewsHow could a SELECT perform better with multiple INNER JOIN
I have a SELECT with several INNER JOIN and some functions such as replace, if.. That one SELECT takes all the information I need, but it takes too long. Is there any way to optimize this SELECT?…
-
0
votes1
answer142
viewsConnect BD sql server to sql
I am trying to connect my sql Developer to sql server, but it is not working. Password and user are correct. They know what the problem is?…
-
0
votes1
answer21
viewsReturn a single line per code
I have a table that keeps a client’s record and its duration in operation. sql needs to return me only the last client term (the most recent one). no code can be repeated follows the result that sql…
-
0
votes0
answers68
viewsThis giving error when I try to insert in my sqlite + java database
package Contas; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Scanner; import javax.swing.JOptionPane; import BancoConexao.Banco; public class ContaCorrente…
-
0
votes2
answers284
viewsSQL Oracle - Clob to Number
I have a table which does not have to be remodeled, it is composed by a CLOB field which has decimal values separated by point ex:(123.12) I need this field to be returned to me in the result as a…
-
0
votes4
answers91
viewsSelect with columns stating incorrect data
Hello I’m having another problem with a database search. I want to make a SELECT that looks for information such as Cod.empresa, razaosocial, ano e valores(somados). At first, the search for…
-
0
votes1
answer46
viewsGroup values in a Mysql PHP query
I am pulling values BD for a table with the results of the query, this search is by date, is working perfectly if I search for a single day, but I would like when to search for two or more days (ex…
-
0
votes1
answer227
viewsQuery Mysql three tables
I am trying to make a query in the MYSQL database, but the query is not getting back what I wanted. I want to make a query where return all modules and modules that the company has with the clause…
-
0
votes1
answer203
viewsCount separate records with filtering condition in another field
Staff need to perform a count of how many distinct records exist in a field, but my filtering condition is based on another field. Example of how the data are organized: PDV | DESC ----------------…
-
0
votes1
answer244
viewsDo you have a better way to format value with space after the symbol of the coin?
Good morning ! I have a need to format the value with a space after the symbol of the coin in Oracle, I managed using the form below: select to_char('0','L')||'…
-
0
votes1
answer73
viewsAdd two columns and subtract with condition
I am trying to sum two columns after subtracting the following way in sql: SELECT sum(valor) WHERE lancamentotipo = "R" - sum(valor) WHERE lancamentotipo = "D" from lancamentos From the above by…
-
0
votes0
answers319
viewsUpdate TIMESTAMP field in On Update Postgres
I have the following table: Create Table tb_teste( cod_key integer not null, data_cad timestamp not null default now(), data_atualizacao timestamp not null default now(), primary key(cod_key) ) In…
-
0
votes2
answers413
viewsHow to create a View in SQL Server by unifying all columns of 3 tables?
I have 3 tables with the same columns but with different records of different periods and no Pks. I’d like to unify them into one view to analyze the data, have some command in SQL that helps me in…
-
0
votes0
answers70
viewsORACLE SQL - Complex Report
Good morning, I need to take a report that is not made available by the system, working with the invoices table. In this table there is the customer data, consumer unit and the debit value. It turns…
-
0
votes1
answer18
viewsProblem when returning a query
Why when I run the query below, it returns records: SELECT COUNT(DISTINCT(dadf332.numped)) AS qtdped, DATE_FORMAT(dadf331.datlan, '%d/%m/%Y') AS datavenda FROM dadf331, dadf332 WHERE dadf331.numped…
-
0
votes1
answer97
viewsUpdate a value in a conditional column by comparing 2 columns from 2 different tables
In a table, I need to enter the value 'ID Related Assembly' in a field, with the following condition: This value can only be entered when the value of the "Id_table1" field is equal to the values…
sqlasked 6 years, 5 months ago Gabriel Marques 79 -
0
votes1
answer59
viewsSelect result feeding other 2 selects
I have the select 1: SELECT DISTINCT SD2.D2_DOC AS NOTA, CONCAT(RTRIM(SD2.D2_CLIENTE), ' - ', SA1.A1_NOME) AS CLIENTE, SD2.D2_COD AS CODPRODUTO, QEK_REVI AS REVISÃO, SD2.D2_LOTECTL AS LOTE,…
-
0
votes1
answer23
viewsHow not to bring repeated description in the parameter?
I have a dataset built for use as a parameter. However, several codes refer to the same description, and I cannot make the descriptions not repeat when placing the description as a search parameter.…
sqlasked 4 years, 9 months ago user178420 1 -
0
votes1
answer37
viewsHow to open connection with 2 tables in php
I’m having difficulty connecting twice in my database, each time will connect to a table the code and the following: Categories <!-- Portfolio Grid --> <section class="bg-light"…
-
0
votes1
answer134
viewsHow to "merge" foreach results
I have a script to upload multiple files in php. Then when uploading, I wanted him to insert in the table photos, the information with the names in this format: "name1.jpg|Nome2.jpg". The query I…
-
0
votes1
answer26
viewsHow to Get Data from an N Relationship for N
Eu tenho uma tabela tb_produtos com idproduto, desproduct, outra tabela tb_categorias com idcategory, descategory, e por fim uma ultima tabela product_category com idproduct e idcategory. If I want…
-
0
votes1
answer253
viewsHelp with Trigger Mutating
I am creating a Rigger that needs to be fired through a table, even creating a COMPOUND TRIGGER it accuses error of mutating, I am aware that I cannot perform a SELECT of the table I am firing to…
-
0
votes1
answer1132
viewsHow to view data from an SQL Server query using PHP?
I’m trying to display data from a table in my database SQL Server, using the PHP, but I’m not getting it. Not error code but also returns nothing. The code is this one: <?php $serverName =…
-
0
votes0
answers87
viewsHow to list a column with update?
Hi, I’m new to sql and need help: I have the following columns: Usuário | Ranking | Posição Fulano 300 1 Ciclano 400 2 Beltrano 500 3 I wanted to know how to put this position 1 2 3... without being…
-
0
votes1
answer40
viewsWhat is the difference between operators <@> and <->
I was studying geometric types and coordinates in SQL, in Postgresql more specifically, and I came across two operators, the operator <@> and the operator <->. What’s the difference…
-
0
votes1
answer117
viewsUse composite key as PK or not?
I have two tables: 1- Contracted Service 2- Payment Contracted Service 1 service may have N payments. I modeled the Contracted Service Payment class as follows: CREATE TABLE…
-
0
votes0
answers38
viewsGives error when executing this query in the system that generates reports
Error executing this query in the report system, but directly from the database returns right> ERROR>>> ORA-00942: table or view does not exist Stijdbcdatabase The consultation is a very…
-
0
votes3
answers1026
viewsQuery SQL, Always show record of a repeating field first
I’m having difficulty listing only one line of each process. The query must always bring the protocols with the last revision. Ex: Show last revision 2 number process only and Show only last…
-
0
votes0
answers14
viewsThe dt_drive column will have the default value as the system date
I have a script in oracle that inside a table called "move" there is a column called "dt_move" and inside this column there is the DATE value i would like to change this value to the date of the…
-
0
votes2
answers51
viewsError Backing Up Windows Forms Database
Guys are having trouble solving this problem! My application is in Windows Forms. I need to perform Backup of data through the application itself, but when I run to perform it informs me of this…
-
0
votes3
answers1024
viewsHandling of sql temporary tables in Delphi
Good afternoon I create in Delphi a Sql temporary table, that is, it does not exist physically. I can even record data to it, but I can’t put the information in a dbgrid: 1) I believe the table so:…
-
0
votes1
answer136
views -
0
votes1
answer32
viewsWork with dates and times in a table
I created a diagram of a gym that has schedules and days, also created two tables on Oracle, which are these: create table dia_semana ( coddia number (6) primary key, dia DATE); create table horario…
-
0
votes0
answers20
viewsapplication error in Homolog
Good morning, I am experiencing a problem in the Homolog version of the project The index 'IX_ReqCompraId_Id' is dependent on column 'ReqCompraId'. The object…
sqlasked 6 years, 5 months ago gabrielfalieri 1,231 -
0
votes2
answers24
viewsOperation using another table field
I need to calculate the amount of consumption of a material. And I wanted to look for the multiplier factor of the unit of another table, but the system presents me the following message:…
-
0
votes0
answers32
viewsC# - Treeview error popular with SQL database tables
I’m in trouble and I need help. I want to popular a treeview with data from an SQL database, but I have an error when putting the data through the code it duplicates everything. My query: select…
-
0
votes1
answer176
viewsLimit the number of rows in the second table?
Hello, good night! I have two tables (Process and Movements). I need to generate a report with the Process data, along with the most recent progress. The query I wrote is returning me all the…
-
0
votes1
answer359
viewsRecover sequential auto increment after deleting some column
I am using SQL server and the scenario is that I have a table with an auto increment id field, for example I have 3 field inserted, in case there are the ids 1, 2 and 3, if I delete the column with…
-
0
votes1
answer23
viewsSQL-Obtain code of the employees who participated in all projects
I have the following tables Employee(Empnum ,Name) Project(Projnum,Name) and Assignment (Empnum ,Projnum,Function) I wanted to build a query in which I return the employee number (Empnum ) that…
-
0
votes1
answer223
viewsSQL SERVER Filter
I have an exercise to do but I’m cracking my head here: "SQL command that brings me the sum of the salaries received per employee and status in the year 2014 of the tables: SALARIES / EMPLOYEES /…
-
0
votes1
answer71
viewsTake only the values that are different in the query
I made a query that brings the values of credit and debit, but I need to bring only the values that are different from these two fields. At the moment I do not know why it is bringing all. Look at…
-
0
votes2
answers79
viewsDo an SQL sub-query
I am trying to make several queries (counting the amount of certain elements) within the same table column, and send each query to a different column. Ex: I have column of names, and I want to…
sqlasked 4 years, 7 months ago Feitosafelipe 59 -
0
votes0
answers23
viewsSQL - Managed Table vs External Table
I bring a less technical SQL question. I use Hadoop’s Hive tool to manipulate the data with SQL. And I would like to know a real situation where I should apply a Managed table and a External table.…
-
0
votes1
answer140
viewsHow to encrypt Stringconnection to a Mysql remote database in C#
I am developing an application that I intend to sell, and so I created a serial verification system, which checks if that activation code is already associated with the PC MAC. I do this by…
-
0
votes2
answers45
viewssql records = 0
want to show qtos customers I have in every city this sql works but for example, if in Sao Paulo I don’t have any customer registration, it simply hides the city from my report how do I get zero…
-
0
votes3
answers7164
viewsLEFT JOIN SUBQUERY
Hello, I’m having a little doubt about SQL since I don’t understand anything about it. I have a table where I am making a select to see the updates with a subquery and do a LEFT JOIN here is the…
sqlasked 6 years, 4 months ago Marcos Schneider 19