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
-
-2
votes1
answer70
viewsNo repetition of SQL SERVER code
I have the following code in sql server. I need to make sure that in the first if it comes out and runs the same instruction that is inside the Else tag not to repeat the code that is inside. How do…
-
-2
votes1
answer1079
viewsselect max(id) of each* record
opa personal, I have a query with this data of the image, I wanted to give a select only in max(id) of each numberExterno to save in another table@…
-
-2
votes2
answers25
viewsMysql inserts different value in reference column passed in query
Hello, when I run a insert in any table that has the users_id column that references the table glpi_users, any value greater than 126 the seat inserts the value 127, for example: INSERT INTO…
sqlasked 5 years, 4 months ago Thiago Lira 3 -
-2
votes2
answers83
viewsHow do SQL sort and randomize at the same time?
I have the following code: (SELECT id, slug FROM anuncios WHERE vum = '$idcategoria' ORDER BY RAND()) ORDER BY publicado DESC I need SQL to sort and at the same time Randomize, only that of the…
-
-2
votes1
answer90
viewsHOW TO CALCULATE PERCENTAGE WITH MYSQL
ID tiposang 1 A+ 2 A- 3 B+ 4 O- Good evening ,I’m doing a project and in my database I have a table similar to this one above, i would like to know how I do to perform a query that shows the…
-
-2
votes1
answer484
viewsHow to enter data (registration) in Sqlite?
Hello, my Sqlite connection is as follows: Connection connection = null; try { // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:database.db"); Statement…
-
-2
votes1
answer63
viewsHow to prevent the creation of records where one of the fields has the value already registered?
Create Table genero_filme( NomeF varchar2(30) NOT NULL, genero varchar2(20) NOT NULL, --Restrições de intregridade --1. Não existe gêneros diferentes com o mesmo nome Constraint fk_Filme_g FOREIGN…
-
-2
votes1
answer1337
viewsIs there a way to add column comments in the same command as create table from Oracle?
There is a way to add column comments in the same command as the oracle create table, just as it is possible in Mysql? CREATE TABLE user ( id number COMMENT 'unique ID ' )…
-
-2
votes1
answer307
viewsORA-00907: Missing right parenthesis, but why?
I was already having problems creating this table in relation to time, but finally, with help I managed to solve the problem. In the end I came across another mistake, but I don’t understand why.…
-
-2
votes1
answer186
viewsCheck Array(STRING) in Postgres column
Good afternoon, everyone, I need to UPDATE a table, but for this I need to compare if the values of an ARRAY(STRING) are inside a column of this table, example: UPDATE tabelaTeste SET versao = '2'…
-
-2
votes1
answer31
viewsSQL - Set Timestamp in Select
How do I set the min("Timestamp") in a select and then return the last data where it is different from this min("Timestamp")? My Code: SELECT min("TIMESTAMP") AS PrimeiroLog, ID, UF FROM bd.test…
-
-2
votes2
answers446
viewsHow to use reserved words in SQL
I need to enter a value in the table, but there is a field with the name 'Status', which is a reserved SQL word. How do I use this field in INSERT? insert into <<tabela>> (status) values…
-
-2
votes1
answer1014
viewsError when adding FOREIGN KEY in already created table
I have a table that I need to change to have a foreign key ALTER TABLE bancocliente.product ADD CONSTRAINT fk_fabPro FOREIGN KEY (cod_fab) REFERENCES bancocliente.fabrica (code); I get the error…
-
-2
votes1
answer876
viewsLaravel Error 4.2 - SQLSTATE[HY000] [2054] Server charset Unknown to the client. Please, report to the Developers
I’m having problems in a web application using Laravel 4.2 the same worked in a Windows 7 environment with IIS + PHP 5.6 but I had to change the machine and create a new development environment.…
-
-2
votes1
answer55
viewshow to group an sql
I have an SQL that when run gives error. Someone could help me to perform the grouping of this SQL? select i.ref, r.nome,n.qtde,sum(n.vlr_tot) from geitens as i inner join gerefer as r on r.cod =…
-
-2
votes1
answer55
viewsHow to use a column calculated in the WHERE clause of SQL?
I have the table Employees who own a field called salary. I need to list only employees who are below the average of all employees' salaries registered in the database. My SQL command is like this…
sqlasked 4 years, 2 months ago Rafael Fachinelli 21 -
-2
votes1
answer228
viewsHow to view month and year only oracle sql
So I’m making a list of exercises, and in a given one, you ask me to make a query that returns the total value of a column, and that those values be grouped by month and year, but the date column…
-
-2
votes2
answers581
viewsHow to pass python variable to sql query?
I am using Mysql as a database. I wanted to be able to pass the value of a python variable as a parameter in this query. Ex: cursor = connection.cursor() variavel_nome_cliente = input('Digite aqui o…
-
-2
votes1
answer42
viewsHow to copy data from one column to another column of the same table
Hello, good afternoon. I have a column table called City where inside it has 5 fields(Codecompleto(PK), Code, Name, State, Nameclear). This Nameclear was created to receive the Name without accents.…
-
-2
votes1
answer102
viewsIs there any way to reduce the if’s of my code?
function updateUser($usuario, $senha, $adm){ //Atualiza informações sobre o usuário $sql_query; $q_senha = ""; $q_adm = ""; $dot = ""; if(!empty($senha)){ $q_senha = "senha=md5('$senha')"; } if($adm…
-
-2
votes1
answer120
viewsSubconsulta returns more than one value
Good night! I have an sql query based on a CTE and I want to take the largest value between a subconsulta, but when I run the main query the subconsulta error returns more than one value appears.…
-
-2
votes1
answer111
viewsCreate mysql table
I need to create, in the database, the table below, and insert the values shown. My question is **what would be the primary key in this table ? **ID_NF ? In exercise asks to only create this table,…
-
-2
votes1
answer25
views -
-2
votes2
answers27
viewsHow to concatenate two fields and use as a key for query in SAS sql proc, as is done in the sql snippet of the example?
Good morning I’m a beginner in SAS and I’m having the following difficulty - Transform the snippet of sql code below to the format of proc sql in SAS. The SQL code would look like this: Where…
-
-2
votes1
answer65
views0097 - missing parentheses on the right. - Can help
I know you already have some negotiations here in the forum about this error 0097 - missing parentheses to the right.. This is my command, you can help me ? select distinct Coalesce(Sum(Case When…
-
-2
votes1
answer24
viewsSQL Server How to link the name of a column to an external variable?
Good morning Srs I made an SQL code that separates an item from each record from a column without repeating, and is working correctly, follows code below: SELECT Tab_Dados_Escolha.Nome_Produto FROM…
-
-2
votes2
answers93
viewsHow to allow null values in a field that was originally NOT NULL in SQL?
I have a table created this way: CREATE TABLE usuarios ( id INT NOT NULL AUTO_INCREMENT, nome VARCHAR(64) NOT NULL, email VARCHAR(255) NOT NULL, PRIMARY KEY(id) ); But I want to change the field…
-
-2
votes1
answer32
viewsPass database and table as parameters to process
I need to make a Stored Procedure of the following kind: USE master GO CREATE PROCEDURE dbo.sp_DR @bd NVARCHAR(20), @VAL AS INT AS SELECT * INTO #TEMP FROM @bd where campo =@val SELECT campo1,…
-
-2
votes1
answer28
viewsSelect from SQL tables
Good morning, everyone! I’m performing the select below: select * from orcamento where status_orcamento = 'A' and data_conclusao_orcamento > 2021-05-31 My question is: Information should only…
-
-2
votes1
answer33
viewsLarval change Auto-increment from Id to id-Year
I wonder if it is possible in washable to change the auto-increment from "Id" to "id-Year" Example: When we have a user with Id:2 I wish it had id: 2-2021 If possible, how can I make this amendment…
-
-2
votes1
answer101
viewsColumn not found using ALIAS in Laravel
I am in trouble when accessing a column in the Windows query Builder, the following code works in Sql Workbench. Vendas::selectRaw('if(faturamento.Codfaturamento is null, vendas.totalvenda,…
-
-2
votes1
answer50
viewsA query to the database that brings the data in sequence
Follow a following code snippet: SELECT user_id, name, firstname FROM vrp_user_identities WHERE user_id IN (27, 2, 1, 365, 142) Returns me an array only with the data I want, but it comes in…
sqlasked 3 years, 3 months ago Caio Oliveira Felix 9 -
-2
votes0
answers28
viewsDifference in Sql Server value To C#
Guys I’m converting this formula here to a C code#: declare @decPorcDescuentoTotal DECIMAL(18, 5), @decImporteCuota DECIMAL(18, 5), @decImporteSA DECIMAL(18, 5), @intCantCuotas INT set…
-
-2
votes0
answers25
viewsUPDATE table 1 with data from table 2
Good morning, I’m having some difficulties to take dice from one table and play to another. I already tried INNER JOIN and could not. I have that data: Table 1 = nft | Column = walletAdress Table 2…
-
-2
votes1
answer17
viewsStore as much data as I want in a tebela column in oracle Apex
I’m creating a page on Apex And I need to create a graph of the reasons that cause the most fines, but a fine can have several reasons. I’m not able to store these reasons so I can generate the…
-
-2
votes1
answer26
viewsUPDATE in two tables at the same time
I need to perform a Update in two tables at the same time, each of which contains two fields that will be changed. However, it is not working! Returns error in INNER Look how I thought: ID_ESTOQUE =…
-
-2
votes1
answer1071
viewsAdvantages and disadvantages of Sqlite
Sqlite is a powerful API for working with structured data, but it requires a lot of effort from the programmer to use it. According to Developer (2018), the programmer faces the famous "Boilerplate…
-
-2
votes1
answer43
viewsSlow query performance
I have a database that has about 3 teras and I’m having problems optimizing some querys. In this example I have 3 tables: Automaker, Car and model. And I have this query that takes about 30m, all…
-
-2
votes1
answer134
viewsProblem with sql query in my ASP.NET core application
I’m having trouble at the time I need to query information in the database through my sql command in my Asp.Net Core application. I’ve done research here at Stackoverflow and I can’t find. Error:…
-
-2
votes1
answer81
viewsJoin in SQL with two tables - users and cells
I have two tables in my database, one containing all users with id and name and other details, and another table containing all work cells, where tie through the user id who is the leader and who is…
-
-2
votes2
answers95
viewsProblem in SELECT INNER JOIN. Appearing ID instead of name
Hello. I would like a SELECT INNER JOIN result to show the record name instead of the record ID. I have researched several topics dealing with the subject here, but I cannot solve this problem. I…
-
-2
votes2
answers804
viewsSAVE VARBINARY IMAGE IN DATABASE
Hello, I have a windows form application, I already have a button to upload via Filedialog to my picture box, displaying it. Follows the code private void button2_Click(object sender, EventArgs e) {…
-
-2
votes2
answers412
viewsHow to use BETWEEN and LIKE together in a Query?
Well I have a table that contains some tables being them ( DATA_INICIAL , DATA_FINAL ) however I’m trying to generate a report that contains the data between the initial and final dates , and who…
-
-2
votes1
answer23
viewsPick up value by selecting from a combobox and send to a php capo
Comes a product query from the bank, and will be placed in a combobox, I have to display the unit of measure (which is in the same table in the BD) in a text field, after the user select the…
-
-2
votes2
answers72
viewsRanking PHP and SQL, without repeating database record
I’m developing a ranking with php and sql, I can list the data correctly. However, I need to make sure that no repeated records appear. My code: <?php include_once('conexao.php'); $rank = "SELECT…
-
-2
votes1
answer29
viewsmysql syntax error
I am running the following script for database creation: create database jogos; use jogos; create table jogo( codigojogo int auto_increment primary key, nomejogo varchar(40) not null ); create table…
-
-2
votes2
answers36
viewscompare case result
I have a table customedio guy numeric, and when the value is less than 0, I want you to bring the message "Negative value" and when it is null, in the different case of larger and smaller than 0…
-
-2
votes1
answer45
viewsQUERY SQL SERVER QUERY
I have a question how to proceed in this case, where I have a query that would need the nserie was ignored or showed only the 1 item of that SELECT ped.codfil, i.seqipd, i.codpro, p.codref,…
-
-2
votes1
answer147
viewsTrigger in mysql copying data in the same table
Good Afternoon, I have a table that contains the id_document (int) AI fields, username and nosso_numero(int). I would like to use a Trigger if it is possible that after I insert a new document the…
-
-2
votes2
answers712
viewsSubquery (SQL error (1242): Subquery Returns more than 1 Row)
I created the following query: SELECT a.`CPF/CNPJ`, a.Cliente, a.Cep, a.Cidade, a.Estado, COUNT(a.`CPF/CNPJ`) AS Novas_Instancias, ( SELECT COUNT(c.`CPF/CNPJ`) FROM relat_instancias c GROUP BY…