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
answer98
viewsConsult the names of the pilots sponsored by a Team
I want to consult pilots sponsored by the 'A' team' I’m doing like this: SELECT piloto.nome AS NomePiloto FROM equipe INNER JOIN piloto ON equipe.idequipe = piloto.idequipe INNER JOIN patrocinador…
-
1
votes1
answer180
views -
1
votes1
answer1147
viewsSELECT in a parent table where ALL children are in the same situation - Mariadb/Mysql
I need to select in a parent table, where all children in that table NEED to be in the same situation. For example: In the parent table I have the following fields: pai_id, pai_nome In the table son…
-
1
votes1
answer70
viewsAdd table B row to table A based on conditions
I have two tables of data, being them: table A and table B. I want to join the rows of table B with A under the following conditions: If a line occurs in B and not in A, add it to A. If a line…
-
1
votes2
answers841
viewsData in SQL ORACLE
How do I apply a function in ORACLE SQL that brings me only records for the current month? BS.: I have a date column in date format (e.g.: 13/09/18). In sql server I applied the function below and…
-
1
votes0
answers341
viewsPL/SQL - Trigger: Can I see the whole line updated in a line after Rigger?
I am studying PL/SQL in college and the teacher passed some questions based on the Human Resources model of Oraclexe itself. The question I’m asking asks a Rigger to prevent an employee from earning…
-
1
votes0
answers102
viewsHelp with sql search and android studio
I made this layout <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"…
-
1
votes2
answers957
viewsError: Column Count doesn’t match value Count at Row 1
include "config_db.php"; $sql = "INSERT INTO tb_produto (NOME_PROD,DESC_PROD,VALOR_PROD,VL_COMP_PROD,STATUS_PROD,COD_CAT,TAM_PROD,COR_PROD,COD_BARRA_PROD,ID_FORN,MAT_FUNC,…
-
1
votes1
answer188
views -
1
votes1
answer44
viewsSelect a list of values and from that list, select the lowest value
I want to select the last 10 inserts of a table and among these 10, return the lowest value. It is possible to do this in a single query? Selecting the last 10 values: SELECT id_relevo FROM relevo…
-
1
votes1
answer31
viewsSQL Filter to not display some items from a table
Good morning! All right? On the website I’m working on, it displays a list of countries that come from the database. However, there was a requirement that the countries sanctioned by OFAC. It calls…
-
1
votes4
answers683
viewsVery slow SQL command
SELECT funcionario.nome, foto.foto, count(*) total FROM venda, funcionario, foto WHERE venda.idfuncionario = funcionario.idfuncionario AND funcionario.idfuncionario = foto.idfuncionario AND gol = 1…
-
1
votes2
answers76
viewsProblem in consultation with Join
I’m having a little problem with the consultation to generate a report. I made a JOIN of the orders table (that will take the report) with the table of customers and products. Until then everything…
-
1
votes2
answers801
viewsupdate sql relating a column with external value
Good morning, I’m having a hard time updating SQL Server. I have the following situation: Table 1 ID Codigo Table 2 ID Nome And I have an excel file like this: Excel Codigo Nome I need to update the…
-
1
votes3
answers134
viewsI’m having trouble summing up the column
I want to sum up the column Value, I know that to use SUM() I also have to use GROUP BY, only I’m not able to make the sum. I don’t know which fields I have to put on GROUP BY. SELECT DISTINCT…
-
1
votes3
answers187
viewsDisplay record when another table has no reference
I need you to just display some record if the field id table noticias has no reference in the field idnoticia table fotos_noticias. SELECT noticias.id, noticias.titulo, noticias.slug,…
-
1
votes1
answer86
viewsUniting arrays where they have a certain equal field
How do I join several arrays in an array when they have the same fields? I have this following array being returned, I would like to group them into a single array where they have the same value pro…
-
1
votes1
answer66
viewscalculating date in update mysql
Good need to update my accounts that are past due more than 5 months, I wanted to do this directly in mysql. The update is like this: UPDATE contas SET baixa_valivade = true WHERE data_vencimento…
-
1
votes0
answers341
viewsSelect in Millions of SQL Server Records
Good morning, I have a database with more than 11 million records, when I make a select on top of the two tables to bring the records the query takes a lot, I wonder how I could improve these…
-
1
votes1
answer4666
viewsHTTP (Post) Bad Request 400 - How to resolve?
I am making a pole, but my server is not emitting an error(400). Below follows the server code. const express = require('express'); const app = express(); const bodyParser = require('body-parser');…
-
1
votes2
answers156
viewsSelect in the database using "like"
I am trying to make a select in mysql database, but would like to use the like, that should receive the value of a java variable. How can I do this interaction? public void…
-
1
votes2
answers95
viewsDifficulty to rescue information from AFFILIATE given a PRODUCT, many relationship to many
I recently started my studies in the area and I have a difficulty in the code. I need to display the data as follows: Product code Product class Product description Name of the subsidiary holding…
-
1
votes1
answer35
viewsError in SQL query
Hello I have a table in the database that in it are stored several times. I am making a query only that this giving error. Consultation: select proximo from (select localizacao.horario as proximo…
-
1
votes2
answers715
viewsWith limit Select output on Oracle
I’m making a bank select and it’s returning me 15 lines. I used ROWNUM to pick up the first 8 lines, only I want to do another select and pick up from line 9 to 15. SELECT * FROM (SELECT DISTINCT…
-
1
votes1
answer330
viewsScript to change table names in the Postgresql database
I have this script: SELECT n.nspname AS schema_name, c.relname AS table_name, c.reltuples::int AS num_reg FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_tablespace t…
-
1
votes0
answers215
views8000 character limit in ASP Classic/SQL server
Dear friends, I’m trying to update a table in SQL Server 2008 R2, but the field only records 8000 characters. The column is set to 'text', but I have tried changing to 'varchar(max)' unsuccessfully.…
-
1
votes2
answers123
viewsQuery to return the first record with specific values
I have to perform a search of the first records with a certain value, let me exemplify. SELECT * FROM users WHERE gender LIKE '%M%' ORDER BY id DESC LIMIT 1; SELECT * FROM users WHERE gender LIKE…
sqlasked 6 years, 1 month ago MAKOTSUAMI 39 -
1
votes2
answers321
viewsHow to give a select and bring the top 1 of each group?
I have a table of processes. That is, each time a process is executed, it generates a new line. I want to give a select bringing the last execution of each process. Follows table example:…
-
1
votes0
answers48
viewsI’m having trouble inserting data into a table with php
My form is like this: <form name="pedidooo" action="cadastrandoPedido.php" method="post" > <?php include './conex.php'; $query = ("SELECT * FROM conta"); $result =…
-
1
votes1
answer152
viewsQuery in Mysql when there are two ids
I have a table in Mysql that records link information from a PABX IP. It always stores the connection with a uniqueid own. But I noticed that time in IVR is also stored in the same table with the…
-
1
votes2
answers171
viewsError #1064 in CREATE PROCEDURE - Phpmyadmin SQL
Message from Phpmyadmin: Mensagens do MySQL : Documentação 1064 - Você tem um erro de sintaxe no seu SQL próximo a '@NumeroSerie INT(11), @Velocidade TINYINT(4), @Direcao SMALLINT(6), @Latit' na…
-
1
votes1
answer242
viewsError at agupar Mysql subquery
I have a select to display 4 fields, but a field that is the valor_pago is from another table, but I cannot use JOIN otherwise the return of the records conflicts So I created a Subquery but my…
-
1
votes1
answer130
viewsHow to get value from a field in SQL using C#?
The idea is that I insert data referring to the same person within SQL, but in different Entities, contextualizing: I have the table Pessoa: create table Pessoa( ID_Pessoa int primary key identity…
-
1
votes1
answer186
viewsUpdate an attribute according to two other tables
Table Company CREATE TABLE empresa ( cnpj char(18) PRIMARY KEY, nome varchar(60) NOT NULL UNIQUE, receita float NOT NULL, pais_sede varchar(26) NOT NULL ); Target table CREATE TABLE destino( cidade…
-
1
votes1
answer199
viewsHow to group data per week in mysql
I am extracting some data and want to know some way to group the data per week. I am giving the SELECT and he’s bringing in last month’s data and I’m already grouping by day, but I need it by week.…
-
1
votes3
answers684
viewsCall database function that receives a list as parameter
People like me do the following... involves database (Postgres SQL) and JPA, I want to create a database function that receives a list of ids as parameter and make a query cm enclosure WHERE IN…
-
1
votes2
answers97
viewsHow to use pseudo names with CONCAT and Mysql?
A question about Mysql asks the result to exit in this answer format. When finishing my solution through a consultation made on Mysql, find the following problem. Below is a first example solution…
-
1
votes1
answer212
viewsOptimize module 10 SQL Server
I have a database created by apróx. a decade, this same bank has several records and obviously, by being in production, can not be changed from day to night. The problem is: The products registered…
-
1
votes2
answers40
viewsDifficulty with Select
I want to make a query of 1 table that has the records: Predio | Local | Produto | FIFO P01 | WH01 | Maçã | 21/02/17 P01 | WH01 | Maçã | 22/02/17 P01 | WH01 | Maçã | 23/02/17 P01 | WH01 | Maçã |…
-
1
votes1
answer171
viewsHow to add a left 0 to a datetime
I need to be able to add a 0 to the left in the hours when sql only takes 3 digits or it is from midnight to 9 am so that the information is ordered! Because if not the information I have is in the…
-
1
votes1
answer775
viewsIs there a possibility to compare schema between different databases in SQL Server?
I have several different comics, and I need to compare their Schemas, but doing this manually can go unnoticed. For context I will use database of smaller proportion than work. Image here. As you…
-
1
votes1
answer193
viewsCreate a Freight Calculation Table in sql server 2012
I have the following question and I need the help of the experts in order to continue my project. I need to create an equal freight table from the image below, only I don’t know if I create a single…
sqlasked 6 years, 11 months ago Junior Guerreiro 617 -
1
votes2
answers1208
viewsselect month and year of a datetime field
I own a field of the kind datetime and I need to make a consultation based only on the month and year. While researching, I noticed that there is the function extract, but it separates only one…
-
1
votes2
answers132
viewsConditions in the SQL
Hi, I have a question in SQL. In the company system there are several registered products, and these products have different sales unit, that is, some are sold by Package, Box, Unit and etc... Every…
-
1
votes0
answers45
viewsDuplicated id s in sql query
friends have an appointment like this: SELECT v.product_id,nome AS Produto,presentation AS Descricao, presentation AS Descricao2, name1 AS categoria, description_two AS descricao, price AS preco,…
sqlasked 6 years, 11 months ago J Junior Carneiro 101 -
1
votes1
answer33
viewsStore a query attribute in a variable
I have the following consultation: <?php define("DATABASE_MS_DB_98", "Cont98"); $conninfo98 = array("Database" => DATABASE_MS_DB_98, "UID" => USER_MS_DB, "PWD" => PASS_MS_DB,…
-
1
votes1
answer584
viewsHow to make an INNER JOIN with two tables in different Banks?
I have two different banks that I make the connection as follows: date_default_timezone_set('America/Sao_Paulo'); abstract class BancoDados { const host = 'localhost'; const novoweb = 'novoweb';…
-
1
votes1
answer93
viewsCalls from Procedure PL/SQL
Studying PL/SQL I came across the following code: CREATE PROCEDURE incluir_segmercado(p_id IN NUMBER , p_descricao IN VARCHAR2) IS BEGIN INSERT INTO segmercado values(p_id, UPPER(p_descricao));…
-
1
votes1
answer55
viewsSummation in SQL
I need to make a report with SQL, that asks me the following situation. In the general report, I need it to stay that way: Produto Quantidade Total Valor total Salpicão 30kgs 810,00 The detail is,…
-
1
votes1
answer74
viewsMYSQL, How do SELECT without grouping identical WHERE values?
Good Afternoon SELECT id, descricao FROM Produtos WHERE id IN ('1','1','2', '3','3'); But the result is id / descricao 1 / Caneta 2 / Lapis 3 / Borracha I wanted it to be according to the table…