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
-
3
votes3
answers144
viewsHelp with select
I’m using the remote select down below: select f.no_equipe, h.no_pessoa_fisica, a.no_cidadao, d.dt_ficha from tb_cds_cad_individual a, tb_cds_atend_individual b, rl_cds_atend_individual_ciap c,…
-
3
votes4
answers702
viewsColumn 'idusuario' in Where clause is ambiguous
I’m trying to make a select with inner join. Rotating the select in the phpmyadmin the ERROR that returns is this: Column 'idusuario' in Where clause is ambiguous <?php $idusuario =…
-
3
votes1
answer261
viewsSelect with specific column - Oracle
I’ve been migrating to Oracle and found a question. In SQL Server I could do so: select coluna, * from tabela How do I get a similar result using Oracle 12c?…
-
3
votes4
answers3251
viewsSelect first name? - Select in bank
I have a table with the following names: João Goldy Alfredo, Gaby, João Antônio, Rodrigo, Maria Aparecida, Mario How can I get only their first name, and those who don’t have a last name, should…
-
3
votes1
answer89
viewsRemove images that are not present in the database
I started working on a site already made by a former programmer who has a page inserting and removing images. However, when it removes, it only takes it out of the database leaving the image there,…
-
3
votes2
answers220
viewsIs it worth putting two foreign keys on a table?
having the tables: Companies Customers empresa_id: foreign key Sales cliente_id: foreign key and the relationships are: Companies and Clients => 1:N Customers and Sales => 1:N Considering that…
-
3
votes2
answers754
viewsMethod that uses a random value as parameter to swap the characters of a string
I have this code that’s working perfectly, but I need random values to appear instead of the X. I want the returned result to be composed of random letters and the position of upper and lower case…
-
3
votes2
answers1861
viewsHow to consult birthday and month in SQL on Oracle?
I saw some examples here, and tried to reproduce them, however, on Oracle does not accept operators as MONTH, then I was unsuccessful. SELECT nome from aluno where month(datanascimento) =…
-
3
votes2
answers566
viewsSelect values that are not in another table
My scenario is as follows: Table Fila I have the Activity table I need to mount a select, taking the values from the row table, however I need to exclude from the row the values that already exist…
-
3
votes1
answer98
viewsHow to Bulkcopy an excel file to an sql table
I wanted to make a bulkcopy from an excel file to an sql table. But you’re giving me this error when I try to send to sql: System.Invalidoperationexception: 'The Columnname indicated 'Transdate'…
-
3
votes4
answers9972
viewsHow to get the month and current year in SQL?
How can I print the current month and year on the screen in sql ? I need the month to be extended. I’m using the query below. select GETDATE() from DUAL Currently it is being printed as follows.…
-
3
votes1
answer1083
viewsHow to add the numbers of a column in the bank that has the same id and repeats?
I have a table called venda_itens that has venda_id, item_id and item_quantidade. I wanted to bring back the item name with the total amount of items sold, and to amount of total items, through a…
-
3
votes3
answers68
viewsHow is Join and WHERE made with multiple tables?
I have 4 tables they are already with Foreign key. aluno: id matricula username curso_id // referencia a id_cursos da tabela cursos, coluna id_cursos. cursos: id_cursos nome_cursos modulos:…
-
3
votes2
answers16608
viewsWhat is the difference between MER (Relationship Entity Model) and DER (Relationship Entity Diagram)?
What is the difference between an MER diagram and an ERI diagram, with examples.
-
3
votes2
answers385
viewsSQL using sum
I have the following structure: | Data |Quantidade|QTCxVer|QTCxBra| |04.09.18| 10 | 1 | | |04.09.18| 30 | | 3 | |04.09.18| 40 | | 4 | |04.09.18| 50 | 5 | | |05.09.18| 20 | 2 | | |05.09.18| 10 | | 1…
-
3
votes1
answer84
views -
3
votes3
answers56
viewsUse prepare statement at a constant value?
$type = 'post'; $stmtPG = $conn->prepare("SELECT count(*) FROM myTable WHERE entry_type = :type"); $stmtPG->bindParam(':type', $type); $stmtPG->execute(); $total =…
-
3
votes1
answer82
viewsIs it mandatory to list tables in a database?
I have a slight knowledge of the database and I know how to use it JOINfor certain SELECTs. I am mounting a simple DB where I have certainty absolute that a table has no relations with others. Is it…
-
3
votes2
answers2282
viewsError with Insert in SQL Server: The Conversion of a varchar data type to a datetime data type resulted in an out-of-range value
Next I have to do a survey and implement a query in the database using Merge and I have to do it using one of the scripts used in class. The problem is that when I run the script the following error…
-
3
votes2
answers86
viewsDoes PDO use DBMS syntax or do they all work?
When considering the use of PDO, one of the main usability is the scope of several databases. Example scenario Different ways to filter 5 records, which vary by database: SELECT TOP 5 campo FROM…
-
3
votes2
answers1435
viewsSQL query taking too long and returning a Time Out error
I am trying to perform a query in SQL. Below is the method: public void excluirVenda(int Codigo) { Conexao conexao = new Conexao(); SqlCommand cmd = conexao.CreateCommand(); SqlTransaction…
-
3
votes1
answer4020
viewsError: Mysql returns the following "Subquery Return more than one Row"
Good morning! I created this query in mysql and by adding the 1st subquery I called "totalEscolas" I get the following error: "Subquery Return more than one Row" without this subquery the code works…
-
3
votes2
answers746
viewsCount how many fields are empty on a MYSQL line
I have a registration table with 53 columns (address, phone, etc). I wanted to set up a consultation that would bring me how many of these columns are empty or NULL, how can I do that?
-
3
votes2
answers979
viewsHow to get value from a database column using C#
I have a web application that uses these 3 tables: Client: CREATE TABLE CLIENTE( ID_CLIENTE INT PRIMARY KEY, CLIENTE VARCHAR(50), ENDERECO VARCHAR(50), CIDADE VARCHAR(30), CEP VARCHAR(9), UF CHAR(2)…
-
3
votes1
answer186
viewsFormula within a Field
In a field I have the value of a formula ((B/2)+ C), where the value B and C comes from other fields, how can I exchange the values of the letters for their real values and calculate the formula? I…
-
3
votes1
answer82
viewsIs it possible to place an HMTL file within the data set?
It is possible to save an HTML file in a column BLOB inside the database and then display as part of the page in PHP? Why do this: it’s more of a learning experiment to compare whether it looks…
-
3
votes1
answer126
viewsHow do I change the order of entering the Mysql database?
I want you to insert something into my Mysql (Phpmyadmin) and place it on top of the last post. Example: Yesterday I inserted Nome: Pedro | Idade: 20 Anos and he was at the top by being the first to…
-
3
votes1
answer55
viewsI need to add values from a table
I own a SELECT and in it I display the sum of the sales values of each product, I would like to make a total sum of the table that made the sum ? SELECT cadpro.descricao, sum(itensped.total_venda)…
-
3
votes1
answer68
viewsAdding data from the same column
Is there any way to make a calculation(sum) using values from the same column? For example: the customer wants to buy a quota in the value of 2000, in the bank I have several registered quotas,…
-
3
votes3
answers924
viewsCan you start a Select (SQL) in the middle of the data table?
Friends, is there any way inside the SQL language (and using mysql BD) where I can start a Select in the middle of a table? For example, I have 500 addresses in the table. I do a search of…
-
3
votes4
answers3071
viewsIf condition in Where SQL Server
I have a Stored Procedure where I need to do a check for a date filter, in case the start date is null I have to do on WHERE take all records less than the final date, otherwise I make a BETWEEN…
-
3
votes1
answer48
viewsSorting multiple columns
The sales table has the following structure: id_venda | nome_cliente | data_venda | data_agendamento | data_cancelamento | data_ligacao Where the "date" fields are all datetime. I would like to…
-
3
votes1
answer36
viewsNOT EXISTS usage in 2 subquerys
I tried to use the NOT EXISTS, but is bringing the results that does not exist in the table tb_pedidoproduto, I believe that the LIMIT is not working: SELECT produto.idproduto ,produto.nomeproduto…
-
3
votes1
answer108
viewsIncorrect Usage of UNION and LIMIT
I want my query to return only the first record of the first table (if there is data in it), because the second table has no repeated data. But he returns this mistake: Error Code: 1221. Incorrect…
-
3
votes2
answers1257
viewsSql Server Error 8623: The query Processor Ran out of Internal Resources and could not Produce a query plan
Sql Server Database 2012 and 2008. They log the following error (sql server 2012): error_reported 2017-12-27 09:14:16.2053050 8623 16 1 False The query processor ran out of internal resources and…
-
3
votes2
answers609
viewsFor/Foreach Sql Server For Each Separate Column Data
I need to execute a command SQL to update a table, the intention of this update would be to update a column with sequential number per company, e.g.: I have a table Sale in this table have the…
-
3
votes2
answers184
viewsBring sql record even if you don’t have the necessary accent
I need to bring a record called Vidraçaria in a survey, how can I bring this record by writing only Glassware in research? Or bring water seeking only agua The search works normally when the word is…
-
3
votes2
answers2545
viewsORA-00907: right parenthesis not found
Hello, I’ve been working with oracle for a little while, and I’m having this problem in the query, returns me the error: ORA-00907: right parenthesis not found, follows below the same: ("""select…
-
3
votes2
answers655
viewsMysql parameter error with C#
string sql = @"UPDATE ivendas SET nritem=(@rank:=(@rank+1)) where id_venda = 20"; try { MySQLBase basemysql = new MySQLBase(); MySqlCommand cmd = basemysql.connection.CreateCommand();…
-
3
votes1
answer941
viewsCircumvent primary key duplication error
Hello, I have the following script, . sql, to create a table and also create a Trigger. SET client_encoding TO 'LATIN1'; CREATE OR REPLACE FUNCTION before_insert() RETURNS trigger AS ' DECLARE n…
-
3
votes3
answers89
viewsAdd values to total - SQL
I have the following query SELECT sum(tbl_purchase_product.sub_total) as sub_total FROM (`tbl_purchase_product`) WHERE `tbl_purchase_product`.`purchase_id` = '3' I have a field called others_price,…
sqlasked 5 years, 10 months ago Sr. André Baill 6,946 -
3
votes1
answer56
viewsdoubt with date in sql tables
good, I have a table with the following information usernum / type / expiredate 1 1 2019-03-03 13:04:42.710 What I wanted to do was to have a trigger in this table that would check the date and when…
-
3
votes1
answer137
viewsEntity Framework returns any type of data with Sqlquery
I’m trying to return dynamic values of a query also dynamic, but I can’t figure out how to get any kind of data from the database. Here’s what I’m trying to do comandoSql = @" SELECT " + NomeCampo +…
-
3
votes1
answer68
viewsMerge results in mysql
I have a database that already performed a query and got the following table: I would like to know how to assign zeroed positions, or replicate subsequent fields that have some defined value,…
-
3
votes2
answers1247
viewsSQL Error [42601]: ERROR: syntax error at or near "Foreign"
When creating this table in postgre sql I get this error message Table creation tipo_agendamento_escritorio create table tipo_agendamento_escritorio( id int8 not null, primary key (id),…
-
3
votes3
answers1436
viewsSQL - Two different WHERE conditions for the same SELECT
I am developing an SQL query which has two different WHERE functions according to the return of a variable. I tried some alternatives but none seem to fit, I need something with this logic: IF…
-
3
votes2
answers77
viewsUpdating multiple records at the same time
I have a list with the id and email of each user id email 1 [email protected] 2 [email protected] 3 joao@gmailcom ... How do I mount an sql statement to update all emails at once in my user table? My…
-
3
votes1
answer54
viewsWhat is the cost of an update when it does not find the record?
I’m doing some Sqls in my Delphi program and I came up with this question, what is the cost to the bank engine when a UPDATE does not find the record according to the parameters of WHERE? My…
-
3
votes1
answer2921
viewsPercentage Postgresql
I cannot perform the percentage of this query . You should take the sum of "valor_convenio" of each municipality and divided by the total sum of the "valor_convenio" : <h3>Entrada SQL SEM…
-
3
votes3
answers81
viewsSimultaneous consultation and amendment
Considering a table similar to this: Tabela : [Frutas] ╔════════╦═════════╦═════════╗ ║ Fruta ║ Cor ║ Mordida ║ ╠════════╬═════════╬═════════╣ ║ Maçã ║ Verde ║ Não ║ ╠════════╬═════════╬═════════╣ ║…