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
votes1
answer70
viewsUse of % in variables
I can not understand what this symbol serves in a variable, I see its use in some points in codes in SQL, Shell Script, C. For what it serves? For example a use of this symbol in Shel Script:…
-
3
votes2
answers247
viewsUpdate two tables with condition
I have the following scenario Two Tables Source Table - Destination Table Both with the same fields [ID] [name] [CPF] The query must go in the [CPF] columns of the two tables, when the [CPF] of the…
-
3
votes1
answer517
viewsDatabase for messaging system with comments and responses
This is my first question. and I don’t know if I’m doing it right. So I apologize in advance if I’m wrong. the doubt I have at the moment does not concern code. but on how to organize the database…
sqlasked 8 years, 1 month ago Douglas Benitez 189 -
3
votes1
answer750
viewsPostgress Crosstab - Return and sql tuple descriptions are incompatible
I’m trying to use Crosstab in postgres but... CREATE TABLE tb_testect ( datahora timestamp without time zone, teste integer ); * Correction INSERT INTO tb_testect VALUES (TIMESTAMP '2016-01-01…
-
3
votes2
answers1100
viewsHow to update or Insert in Mysql in the same query?
In Postgresql you can use the upsert. It checks if the line already exists, if yes it does update, otherwise it does Insert. In Mysql I’m not able to do this, I saw some talking to use INSERT ... ON…
-
3
votes4
answers1202
viewsWhat kind of data to use for sale ID
I have a Windows Form application developed in C# and with SQL database. One of the functions of the system is to carry out SALE for several different COMPANIES and in several different POS (point…
-
3
votes1
answer1479
viewsQuery with random result
I have the query below, used in an internal routine, for distribution of items for separation in data collectors: Select distinct IP, USUARIO, DATA from PCN_ROMANEIO_ACESSO PRA Where pra.STATUS =…
-
3
votes1
answer1722
viewsWhat is the real difference between the operator '=' and LIKE?
Doing another test (rs) in a database I have in Mysql, I realized that: SELECT * From client WHERE uuid = '1kvsg4oracxq' returned the same result as: SELECT * From client WHERE uuid LIKE…
-
3
votes3
answers996
views -
3
votes3
answers6518
viewsHow to access the code behind a Stored Procedure?
How can I access the code behind a stored procedure? I’m using Microsoft SQL Server Management Studio.
-
3
votes1
answer459
viewsExecute 2 querys or more
I wanted to execute 2 darlings in C# when the button is clicked, but I can only execute one. public static void excluireventos() { string connectionString = Conn.tank(); using (SqlConnection…
-
3
votes2
answers4957
viewsHow to search records from the previous month?
I need to get the data from the 1st to the 30th of the previous month, I’m using this syntax. someone could help me? SELECT SUM(DIFERENÇA)as Mesanterior FROM TOTALIZADOR WHERE NID = 252 AND DATAHORA…
-
3
votes2
answers505
viewshow to specify values to sort sql server
Good afternoon! Guys, I have the following query below, however, I want to order by specifying some records. Attached for example, is the query generated and I want the column Value to look like…
-
3
votes1
answer68
viewsSecurity in php failing
I created a small security code for my login system, to prevent people from composing the administrative panel link and pasting and being able to access it. <?php ob_start();…
-
3
votes1
answer11657
viewsDuplicate database record with new id
I have a table in the database called user, with n fields, how can I duplicate a particular record only with a new id? insert into usuarios * select * from usuarios where id = x? Obs: this id is a…
-
3
votes1
answer103
viewsDelete select value by comparing to another table
Good morning, I am developing a scheduling site, however, I am having a huge difficulty trying to display only the schedules that are available. Explaining: There is the table Agendamento´, onde…
-
3
votes1
answer49
views -
3
votes2
answers142
viewshow to query data in a table that is not related to the other table?
I have the following tables: CREATE TABLE IF NOT EXISTS `categoria` ( `id` INT NOT NULL AUTO_INCREMENT, `nome` VARCHAR(25) NOT NULL, `descricao` VARCHAR(100) NULL, PRIMARY KEY (`id`)) ENGINE =…
-
3
votes2
answers782
viewsHow to use JUNIT to test void methods of my DAO class
Hello I have a DAO class and I want to implement tests with JUNIT, but many of the methods have the return void. Here’s a piece of the class that makes up the DAO package public class ExemplarDAO {…
-
3
votes1
answer93
viewsGroup SQL queries
I have these queries below, independent, and I’m having difficulty grouping them a same query result, IE, leave the 6 columns requested by select in the same consultation. SELECT codigo_processo…
-
3
votes1
answer97
viewsExpression nickname with SUM is not working
I’m trying to make a SUM in a query that performs some calculations. Follow the example: SELECT SUM ( (qtd - qtd_devolucao) * valor AS total) FROM produtos WHERE id_pedido = '47' I’m having the…
-
3
votes1
answer48
viewsEncrypting Function Script and Procedures in MSSQL
A doubt, I have some functions and procedures customized and I do not want my client (who has access to the bank) to be messing with their script. Does anyone know any native MSSQL way of encrypting…
-
3
votes1
answer98
viewsSQL: MAX(data) with wrong results
Good guys, have a problem, when searching for the highest date by grouping by id, I get wrong value in the Obs field. Query in use: SELECT a.n_func,a.id_sk, a.data, a.obs, b.maxdata, b.obs FROM…
-
3
votes1
answer2406
viewsUsing the Firebird SQL case statement
I’m trying to make the following sql in Firebird. select distinct tb_proostarefas.*, (case WHEN (tb_proostarefas.dt_prev is null and tb_proostarefas.dt_vencimento < date) then 1 When…
-
3
votes2
answers174
viewsUse of LINQ to query a collection
about min: I come from JAVA and recently I am learning c#, but I have a doubt about the use of LINQ. Many tutorials speak of the wonder that is LINQ but I so far can not understand its usefulness.…
-
3
votes2
answers125
viewsDoubt regarding Count in SQL command
I need to count the amount of supplies available in stock according to your codigoSuprimento, for this I created the following sql command: select count(codigosuprimento) quantidade,…
-
3
votes1
answer70
viewsWhen relating two tables, is the correct one on the SQL side, PHP or whatever?
I have this doubt of what is preferred to do when I need data from the two tables to get the result. I always did the comparison in PHP, but I learned the SQL relationship commands that could help.…
-
3
votes1
answer178
viewsBug script to delete entire SQL SERVER database
I have the script below to drop EVERYTHING from the database, but in one of the database I have the processing that needs this script happens a bug, for some reason it can not run the first time I…
-
3
votes1
answer6636
viewsHow to calculate the average using conditions in SQL Server?
The question asks me to show the number of students with averages greater than 7, less than 7 or equal to 7 for some tables I have here. Thus showing: How to create this column of Description?…
-
3
votes1
answer1316
viewsHow to Make Select Self Relationship N:N
I am unable to perform an SQL query with relationship N:N. I have a table of users and another with self relationship user_has_usuario, who will be registered responsible and students (from a…
-
3
votes1
answer1053
viewsValidate form and insert into Database with PHP
Hello I’m still a beginner in PHP and stagnated validating the contact form of my site. Complete client-side validation using Javascript, but on the server-side you still haven’t completed the task,…
-
3
votes1
answer39
viewsAccess SQL Server 2008 data from Mysql
Does anyone know if I can access data from an SQL Server 2008 database from a Mysql database? It would be something like Linked Server, but the other way around.
-
3
votes1
answer820
viewsPDO Insert multiple lines into a single Insert using bindParam
I have a default function that I use for all of my Inserts (when they only have 1 Insert at a time), which would be: insereRegistro($sql, $param=NULL) { $query = $conn->prepare($sql); //Converte…
-
3
votes2
answers1911
viewsMysql - Search number in a string
SGBD: Mysql I have a table with a column of the type Varchar, with the following data: id Descrição 1 Pgto NF 66096 Lg Sistemas vcto: 01/10/2016. 2 Pgto NF 66096 Lg Sistemas vcto: 01/10/2016. 3 Pgto…
-
3
votes1
answer124
viewsDump Database
Is there any way of knowing whether or when a DUMP of a database?
-
3
votes1
answer577
viewsQuery in Mysql does not order correctly
I have a game table called game, a table of gaming platforms called plataformas and a table that makes the N-to-N relationship between the two calls game_plataforma. I have a query that has to fetch…
-
3
votes2
answers1003
viewsHow to display total rows of a table in a label
I don’t know how to pull the total lines of a table, code: public string Eventos { get; set; } SqlCommand comando = new SqlCommand("SELECT count(*) FROM Active", conn); SqlDataReader leitor =…
-
3
votes1
answer219
viewsHow to evaluate which command to use between truncate/delete
I was reading about these commands Truncate table and Delete from, where I saw this explanation Truncate table - This command removes the watermark from the table by cleaning the same for a next…
-
3
votes1
answer985
viewsHow to make a "select like" to a subquery result
I need to make a select in sql server 2014 the result of a subquery, for example: select * from tabela2 where codigo like ("1;3;4","3","1;2;5") Where ("1;3;4","3","1;2;5") is the result of subquery…
-
3
votes1
answer3140
viewsHow to convert this date to datetime in oracle?
Correct way to convert the date '27/12/2016 16:31:39,137000000' for datetime(timestamp(6)) in the oracle? Some unsuccessful attempts that result in error ORA-01821: formato de data não reconhecido…
-
3
votes1
answer258
viewsWhy using a column of a virtual table makes an SQL in Oracle slow
Good. Without wanting to leave the subject too "gassy" but wanted only tips of things to investigate in the environment. I have an SQL that uses a virtual table, for a number of reasons that are not…
-
3
votes1
answer7439
viewsReturn a PDO query in an array
How do I perform a query with PDO and return the results in a array. Ex: I need to make a query that returns me 10 rows, each row has 3 columns <?php $equipe1 = $_POST['equipe1'];//Pega o Nome da…
-
3
votes1
answer505
viewsUpdate in two SQL Server tables
How do I perform an update at the same time on two different tables? I have a table called Tarefa and another call VinculoReferencia, both have the field Taridinclusao where is this field that needs…
-
3
votes4
answers5888
viewsSelect with multiple Left Joins Sql Server
I took an example of people registering with the following structure: I’m trying to make a SELECT in tblPessoa with JOIN with the intention that select returns data from the table in which Id…
-
3
votes1
answer2389
viewsThe result of the string concatenation is too long
I made a select with the function LISTAGG to concatenate a field of my table, however the error is returned: ORA-01489: the result of string concatenation is too long Query (SELECT LISTAGG…
-
3
votes1
answer2359
viewsPerform direct calculations in the sql query
How could you perform a series of calculations directly in the sql query, as there is SUM() that performs the sum would have some way to add one column to another and decrease another? $sql02 =…
-
3
votes1
answer46
viewsError Parameter 5
When I try to change the already performed record, issues the No value specified for parameter 5. The code: private void alterar() { String sql = "UPDATE tbusuarios SET usuario = ?, telefone = ?,…
-
3
votes2
answers1084
viewsPass SQL value to a VB.Net variable?
I have this code that runs an SQL: strsql = "select Nome, Senha from users where Nome=@field1 and Senha=@field2" objcmd = New Data.MySqlClient.MySqlCommand(strsql, objconn) With objcmd…
-
3
votes2
answers2800
viewsHow to get the records from the last 15 days - Postgresql
I have a table called Entrega where all deliveries made with their respective dates are stored, how can I bring only deliveries from the last 15 days? Doing so I can bring deliveries from the day 10…
-
3
votes2
answers86
viewsORM that can connect with 2 BD types (SQL or HANA)
Any suggestion of a ORM or Micro ORM that can connect/manipulate 2 different database types, not Imultaneos? The scenario: I already have an application that uses SQL, I need to adapt it to accept…