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
answer34
viewsAdd Count to a query
Good morning, I’m trying to sum up a Count in a query that returns three columns in the oracle the total diet column being the event count for that group! NM_DIETA TOTAL_DIETA DS_SETOR Extra: fruit…
-
0
votes0
answers16
viewsMYSQL ERROR #1442 - Delete with a data-based Function of a select
I was trying to remove repeated values from a table, I needed a group by and a limit, I could only think using an extra Function: DROP FUNCTION IF EXISTS func; DELIMITER // CREATE FUNCTION…
-
0
votes0
answers12
viewsExecute a Mysql command(event) if the "item" is not in two separate databases
Hello is basically the following is a Webgame where every 5 min runs the regeneration command, the command would be this: UPDATE `_personagens` SET vida = IF( vida +(vida_m * 0.05)> vida_m,…
-
0
votes0
answers10
viewsAt least one of the resulting expressions in a CASE specification must be an expression other than the NULL constant
INSERT INTO FILAS_CARTOES (COD_ASSOCIADO, SEQUENCIA_ADICIONAL, COD_USUARIO, DATA_REGISTRO, PROVISORIO, GERAR_SMS, STATUS, PRIORIDADE) VALUES ( @COD_ASSOCIADO , CASE @SEQUENCIA_ADICIONAL WHEN 0 THEN…
-
0
votes0
answers28
viewsTrigger with mutant error even using Pragma Autonomous_transaction;
I’m a beginner and I’m having trouble solving a simple problem: I created Trigger below: AFTER INSERT OR UPDATE ON CARRO FOR EACH ROW DECLARE Pragma Autonomous_Transaction; V_REFERENCIA INT; BEGIN…
-
0
votes1
answer32
viewsDISTINCT in a WHERE Oracle
I need to return the last two purchases of each table item NOTA_FISCAL_ENTRADA_ITEM, but returns column values VL_UNITARIO_ENTRADA_EST different. That is, if in the last two purchases the value is…
-
0
votes1
answer43
viewsAdd the result of a variable to another variable
I have the following problem: I developed a report in iReport 5.5.1 where I added the data of a column into a variable because I need to show this total, and then I need to take these totals and sum…
-
0
votes1
answer30
viewsSum values from a column in the table where the date repeats, in a SUB-SELECT
Dates are different in your hours as this example: +---------------------+-------------------+-------+ | DATA | callid | tempo | +---------------------+-------------------+-------+ | 2021-08-01…
-
0
votes2
answers19
viewsHow to use select with php and Pdo
Hi, how are you? I am learning database with php, was creating a class named crud where there is a select function to remove data from the database, however, after select, the result is always 0,…
-
0
votes0
answers15
viewsQuery between two tables is returning NULL value
i am trying to make a query that will join some tables in my database using a Join. The tables are as follows:: Table 1 - RESULTADOS_SIGLAS +--------------+-------------+-------+ | ID_RESULTADO |…
-
-1
votes1
answer1241
viewsCopying record of table in itself via vba
Can you copy a record from a table and insert it in itself? I wanted to copy a record into a new one on the same table. INSERT INTO Produtos ( Produto, Preco ) SELECT Produtos.Produto,…
-
-1
votes1
answer604
viewsProblem showing a "select Count(*)" in PHP
$result = $SQL->query("select count(*) AS codes_count from gamecodes WHERE gamecode='.$SQL->quote($gamecode).' AND alreadyused='N';")->fetch(); $counts = $result['codes_count']; echo…
-
-1
votes1
answer155
viewsGroup Mysql Values
Dear, I have a table with the configuration: Tipo Medida Valor 1 0.2 5.00 1 0.4 6.00 1 0.1 5.00 1 0.3 5.00 2 0.1 3.00 2 0.2 3.00 2 0.3 5.00 2 0.4 5.00 I would like to group the values where they…
-
-1
votes1
answer121
viewsSum query
I’m having some kind of problem with this query, but what I want to happen is for all values like: Goals Scored, Assists Made,Key passes etc, to make sum for each Player ID making them appear only…
-
-1
votes1
answer290
viewsCampo Jtextfield
How to convert a component JTextField for type Date? How to do research? How to create a query for the bank by returning a list of orders according to a date range? Follows the code currently used:…
-
-1
votes2
answers457
viewsCheckbox concatenating string several times
I wanted to click on checkbox and then register, save the default value and service name in the database (description). However, the description is a problem for me, because when the user marks and…
-
-1
votes1
answer360
viewsSearch by age in birth date field
Hello, I have a patient table and I need a query in which the user informs an age and returns the existing records. But I don’t have the age field in the table but date of birth.
-
-1
votes2
answers1112
viewsHow to select all columns of a row?
It is possible to select all columns of a row? I have a function where, on the screen where the user will be created, a validation is made in the first field typed to verify if the ID user I am…
-
-1
votes1
answer878
viewsTiered login system with access level
Good morning, I am making a software for completing a course at school, and I need to make a login system with access level (I am programming in layers and using SQL SERVER 2012). I saw a tutorial…
-
-1
votes1
answer356
viewsSubselect within a field
I am displaying several fields through a SELECT: SELECT razaosocial, nomefantasia, cnpj, ie, im, endereco, endereco_numero, endereco_complemento, codCedente FROM cliente WHERE razaosocial LIKE…
sqlasked 9 years, 1 month ago Sr. André Baill 6,946 -
-1
votes1
answer194
viewsquestions on category and subcategory
good afternoon I created a product category system in the store I am riding on it I have a page that calls for get the categories but I have a problem I have more than one category per product and I…
-
-1
votes1
answer296
viewsHow do I validate specific fields in SQL
I have the following code made by Amon: select id, disponibilidade, tipo from clientes where cliente = '$cliente' AND status = '2' AND (tipo <> '0' AND (disponibilidade <> '0' OR vanual…
-
-1
votes1
answer187
viewsWhat’s worse a "Where" or "Join"? Which is more expensive?
What’s worse a where or join? Which is more expensive?
-
-1
votes1
answer40
viewsALTER TO - SQL SERVER
in my Bank I have 2 stored procedures ,dbo. A and dbo. B . in the database. A there are the parameters @name , @street in the process dbo. B there are the parameters @cep , @phone however I also…
-
-1
votes2
answers672
viewsCan I use IF inside FROM in Mysql?
It would be possible to do IF within the FROM? I looked but couldn’t find anything about it. Follow an example of what I want to do: SELECT usuario.* FROM ( SELECT IF( (SELECT COUNT(*) FROM pessoa)…
-
-1
votes2
answers239
viewsMultiple assignment in Mysql
How to assign multiple values to a table attribute in Mysql? For example a table where a customer can have multiple phones, and in the assignment can be passed the various customer phones at once.…
-
-1
votes1
answer3634
viewsIt is possible to disable the Primary key of a table
I was wondering if it’s possible to disable a Primary key from a table. I’ll explain why you have to disable Prime Key. I have a table B that has a foregein referring to table A, but I need to…
-
-1
votes4
answers582
viewsHow do I SELECT then INSERT
How do I select and return more than 1 record does the UPDATE and return 0 records does the INSERT ? Look how I did it here only it’s not working: if(isset($_POST['submit'])){ $query =…
-
-1
votes1
answer204
viewsDelete rows in multiple tables
I’m trying to erase information from two tables at the same time that are connected to each other but I’m not succeeding, give me this error: Somebody please help me?…
-
-1
votes2
answers241
viewsPHP - SQL: show the user’s email from the database
Guys, here’s the deal: Made the user registration on the site, it saves in the database (obvious). This is the code of the connection to the database (this is correct?): <?php echo $sql= "select…
-
-1
votes1
answer433
viewsAndroid communication and SQL database
I am developing a web application that aims to manage the stock, sales projections, etc. of a company. However, the sellers travel to carry out sales and have requested that they also make an…
-
-1
votes1
answer57
viewsQuery returns nothing
I’m making an application on android using sqlite but I’m not able to return anything with these Where statments. I have the following table: id day month valu1 valu2 and the following cursor:…
-
-1
votes1
answer111
viewsHow to make an SQL do the correct property count under certain criteria
I have the following SQL that correctly counts the number of properties: select clientes.id, clientes.nome, clientes.status, clientes.cliente, clientes.tipo, clientes.disponibilidade, imoveis.id,…
-
-1
votes3
answers795
viewsHow to do a query that only refers to the DIA of a date?
I have a MYSQL bank and I need an SQL that refers to the PAYMENT DAY in the DAY field (this field will only have the DAY of the month that the client chose to make the payment, this field is of the…
-
-1
votes1
answer48
viewsHow to have more than one value for another table?
Good people, I come with a doubt that has been chasing me for a long time. Let’s get to it: I have the table X however values of table X I picked up at table Y. How to store more than one value in…
-
-1
votes1
answer55
viewsDelete record from database
I’m trying to run the following line: $sqld = "delete FROM ata where convocatoria.nome_entidade='$ent' and convocatoria.cod_convocatoria=ata.cod_convocatoria"; mysql_query($sqld); I tried direct on…
-
-1
votes1
answer1899
viewsCall Procedure inside another
I need to create a precedent enviar_email_servidores call in another pr_envia_email. The term to be called (pr_envia_email) has the function of sending email, and I need the message sent to this…
-
-1
votes1
answer51
viewsProblem with functions
Hello, I have the following problem, I have a view in the bank that makes a group by, and I have another table GraficoCor, I want to make it every time While of the first function make an increment,…
-
-1
votes1
answer63
viewsSQL - Problem Naming Variables
Since I don’t know how to explain my problem, I’ll give you an example: select cod_prod, sum(quantidade) as "Quantidade 2013", sum(quantidade) as "Quantidade 2014" from itens group by cod_prod…
-
-1
votes3
answers516
viewsError in POSTGRESQL Database Creation
I am having the following error when creating a POSTGRESQL database: SQL CODE: CREATE DATABASE pesadaum; CREATE TABLE user( user_id int PRIMARY KEY NOT NULL AUTO_INCREMENT, email varchar(255) NOT…
-
-1
votes1
answer80
viewsCopy a column from a given table to another column from another table
I’m trying to do the update below, only I’m having difficulty. I’m grateful for the help!! UPDATE pctabpr set pctabpr.ptabela = (SELECT ptabela FROM pcembalagem WHERE pcembalagem.codprod =…
-
-1
votes2
answers87
viewsSQL + Left Join
I have 3 tables produto, carrinhoProduto and venda I wanted to know the products that did not sell in the year 2015: SELECT p.idProduto,p.descricao as 'Produto',datepart(year,v.dataVenda) as 'Ano'…
-
-1
votes2
answers212
viewsComparison between decimal numbers
I have 2 posts on a table, with prices 500,00 and 88,98. When I run to sort according to the highest price, Mysql returns me that 88.98 is higher than 500.00, the "price" field is a string, because…
-
-1
votes2
answers524
viewsHow to remove the decimal separator from a result?
In the sql query I have a total order value multiplied by 1000: Total value: 195.41 Value Viewed: 195410.00 How could I remove the separator? SELECT CAST(CONVERT(varchar, CAST(195410.00 AS money),…
-
-1
votes1
answer583
viewsHow to update to table with Foreign key
I have table discipline and table teacher. The teacher contains discipline. How do I change the name of the discipline and automatically change in the teachers? I’m a little confused about using On…
-
-1
votes1
answer32
viewsHow not to select lines with values from an informed list of values
Instead of using the logical operator of different !=, would like to use a code that performs the query disregarding a list of values as in In only that the reverse. Select from teste where teste1…
-
-1
votes1
answer110
viewsQuery to join specific tables
I need to put together three different tables. But the result I want is: When there is the reference it must join, when there must be no blank or NULL. My structure: Table contact…
-
-1
votes1
answer1266
viewsHow to convert sysdate to milliseconds in Oracle?
How to convert sysdate for milisegundos directly on Oracle? I need to give the same result as the code below in java, but directly in query: String s=df.format(Calendar.getInstance());…
-
-1
votes1
answer82
viewsQuery with a specified date - PHP
Hello, I have an order query, where I just wanted to show the orders of the current day and also the orders of the next day, where the orders of the next day would only appear those that would have…
-
-1
votes2
answers138
viewsdoubt with select sum() Mysql
I have these two tables, January and February: each field corresponds to the day of the month, D1= day 01, etc. I need to create a select that shows the monthly value of each account plan, example:…