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
answer80
viewsSQL is importing dates in different format
I am having problems when selecting a date column in SQL Server. It turns out that my data is in format dd/mm/aaaa and when I select this column the SQL reverses getting aaaa-dd-mm and it actually…
-
3
votes1
answer837
viewsPrefixes in SQL Sentence
In SQL Server it accepts only 4 prefixes in the sentences, e.g.: Select * from pmv.banco.dbo.tabela. In this case, I am using a client Linked server. However, when I reference some field of the…
-
3
votes3
answers334
viewsError using LIKE to search by name
When I used Mysql I could use the LIKE ? to do searches by name, code, etc... Now in SQL Server I’m not getting. I have a Textfield and a search button, I want to take the value of textField and…
-
3
votes2
answers180
viewsSql - Natural Ordering - Varchar
Situation I need to perform Natural string ordering. Example Processo 1 Processo 2 Processo 3 Processo 10 Processo 11 Processo 12 Standard Order. (ASC) Processo 1 Processo 10 Processo 11 Processo 12…
-
3
votes1
answer336
viewsMount SQL to generate a dataset and popular a Treeview
I have a database here and I want to mount an SQL to generate a dataset in Delphi and then popular a Treeview. The figure below shows part of the seat, but that is the general structure of it:…
-
3
votes1
answer209
viewsShow more than one dropdown column value C#
How could it show more than the value of a column of a dropdown? I tried the following method: private void BindDropDownList() { DataTable dt = new DataTable(); string localidade = string.Empty;…
-
3
votes2
answers3255
viewsI need to return the null values of this Inner Join
I have this select mysql: SELECT credor.nome, banco.descricao FROM credor INNER JOIN banco ON (credor.banco = banco.codigo) He returns me all the creditors and their respective bank, but if the…
-
3
votes1
answer332
viewsFind the least-appearing numbers in the records
Personal greetings. I have a sort of table like this: reg num0 num1 num2 num3 num4 num4 1 4 2 5 8 10 15 2 3 7 8 15 20 21 3 14 10 6 21 17 1 4 1 4 8 10 16 7 5 9 3 2 1 8 15 I need to find out what the…
-
3
votes2
answers477
viewsList every month in Query or PHP?
I need to list every month within a period, including those that have not moved, example below: My Query: SELECT LEFT(B8.B8_DTVALID, 06) AS VALIDADE, SUM(B8.B8_SALDO) AS VENCIDO, 0 AS VENCENDO, 0 AS…
-
3
votes3
answers727
views -
3
votes2
answers8499
viewsSubselect in Oracle bank
I am trying to elaborate a query and within one of my joins it is necessary to be made a subselect to ensure the integrity of the query as the example below: select t01.teste from teste t01 left…
-
3
votes1
answer38
viewsSQL checking data content
I’m making a search system for my blog (it already looks for post category and tags). Is there any SQL command (or if the SQL itself already does it) that makes it check all the contents of the data…
-
3
votes1
answer62
viewsSelect max in nested queries
I have to select the candidate who has more publications than any other candidate. select candidato.nome, Count(1) as nr_publicacoes from candidato, cv,ficha_inscricao, publicacao_cv where…
-
3
votes2
answers37
viewsDoubt with sql command in c#
SqlCommand comm = new SqlCommand("UPDATE Contatos Set Telefone=" + " ' " + txtTelefone.Text + " ' " + ",Cidade=" + " ' " + txtCidade.Text + " ' " + ",Email=" + " ' " + txtEmail.Text + " ' " +…
-
3
votes1
answer296
viewsHow to mount a query with optional conditions?
In the example: SELECT * FROM exemplo WHERE ID in(2, 3, 4) He brings if he has these ID at the bank. How to mount a query which places this condition only if the array in PHP have elements? PHP:…
-
3
votes1
answer260
viewsIncorrect information when loading bigdecimal entity
I have a table, that one of your columns is a Numeric(25,10) that will be shown the rates. But there are records that will be zeroed ( 0.0000000000 ) In my entity you own that fee, as a Bigdecimal.…
-
3
votes1
answer2466
viewsUpdate in date field updating calculated field
I have in my table a Dtbehavior field of type Datetime. Besides this I have three other fields computed as follows: DAY: (datepart(day,getdate())) MES: (datepart(Month,getdate())) YEAR:…
-
3
votes1
answer440
viewsProblem generating report between dates
I have a field DATETIME with a date and time: 2015-08-06 08:50:28. I’m trying to generate a report by passing two parameters, Data_Inicial and Data_Final so that I can get all the bank dates that…
-
3
votes1
answer1243
viewsPass multiple parameters to an SQL query
Let’s say I have the following CPF's: 65568752877 86924355382 55317961378 82331493146 I would like to pass them as a parameter in a consultation SQL, I’m trying this way: Snippet ... " AND…
-
3
votes2
answers46
viewsSelect of dates
I need to make a select that brings me occurrences that the initial date of a leave is less than 3 years from the date of an employee’s admission Follow below excerpt from my code. SELECT * FROM…
-
3
votes1
answer640
viewsMaximum size of sql query text
What is the maximum size of an sql query string? (Maximum query statement) Ex: SELECT * FROM ajuda WHERE (id = 1 OR id = 2 OR id = 3 OR... @Edit: The bank I was using (access) has other limits…
-
3
votes1
answer192
viewsSelect, by quantity, items that match conditions
I have a question when it comes time to mount a query. I’ll set up a fictional scenario to demonstrate. I have the table quantidadeQuestoes with the fields: cod_nivel cod_categoria cod_difficulty…
-
3
votes1
answer79
viewsCluster difficulty and Where clause in Mysql
I need to search the database for the last 4 most recent records, the column being exr_exa_id is in agreement with the informed Ids, and exr_exa_id may not be duplicated. I tried to group in some…
-
3
votes1
answer152
viewsCatch max value inside a while that is inside a cursor
My doubt is the following: I have my cursor for the interaction line by line and within it I have one while for horizontal interaction. I am trying to popular a table whose PK does not have…
-
3
votes1
answer4727
viewsSelect the 3 highest values
I have a table that has the following data: id_indication, id_user,lg_client A user can indicate multiple clients (lg_client = 1), would like a select that searches for the 3 users that indicated…
-
3
votes2
answers321
viewsInner Join 3 tables
I have the following appointment. $cmd = "SELECT ofertas.id, ofertas.titulo, ofertas.descricao, ofertas.valor, ofertas.user_of, ofertas.categ, ofertas.local, ofertas.fav, favoritos.id_oferta FROM…
-
3
votes1
answer159
viewsHow do I select multiple fields in the same query?
I created a dummy bank with the following structure: Below are also the numbered SQL Server scripts for database creation, if necessary. SQL Fiddle Now, what I want to do is make an appointment…
-
3
votes1
answer546
viewsWorking with high processing load in a table
What are the possible strategies of database modeling in a scenario where one has a specific table that receives a gigantic load of statements of insert, update and delete, in addition to high data…
-
3
votes1
answer128
viewsMake query not showing some results
I have a table of CPF where the CPF’s registered. I need to make a SELECT where display all registered Cpfs, least 3 CPF’s. Something like: SELECT * FROM cpf WHERE cpf_id <>…
-
3
votes2
answers319
viewshow to take an element from a table
Speaking of variables that can be declared within Begin, I saw that it has Declare and set only that I don’t know when to use them. I saw that you have set @x, set x, set x = x+1, set x := x+1; they…
-
3
votes1
answer1804
viewsSelect taking the difference between Sqlite dates
I wanted a select to give me the following sentence comparing two dates, example: "2015-03-12 13:00"e "2015-03-12 14:15". My return would be something like: 0 days 1 hour and 15 minutes to go... I…
-
3
votes1
answer2299
viewsHow to clear Mysql’s cache of queries?
How do I clear the cache of darlings, stored by Mysql? What is the command?
-
3
votes2
answers619
viewsStored Procedure for log data insertion
I need to create a Stored Procedure in my SQL Server database. The purpose of this Stored Procedure is to record data in a Log table, which has three fields: date, time, ID of who logged in. Date…
-
3
votes1
answer726
viewsReturn values of all months of the year extracting by month
I’m with the following SELECT: SELECT coalesce(sum(vs.total), 0) FROM tabela_exemplo t WHERE extract(year from t.data_entrada) = extract(year from current_date) GROUP BY extract(month from…
-
3
votes3
answers2223
viewsHow to group for weeks using sql?
I have the following problem . I have several requests , and I want to group them for weeks. I’ve seen several examples ,almost none helped me, I wonder if there is a function that when you put it…
-
3
votes3
answers2863
viewsCopy data from one table to another without entering field by field
Does anyone know the SQL command that copies the data from one table to another table, without having to clarify all the fields of the original table? I know there is a way but I forgot how it does…
-
3
votes1
answer556
viewsFirebird C# standard Singleton
I am using the following function to connect to the database, I am programming in C# in Visual Studio 2013. namespace WindowsFormsApplication1 { static class Conexao { private static String strConn…
-
3
votes2
answers1567
viewsMuch interface query for many SQL server
Hello, I have a question to make a select in the SQL SERVER. I have 3 tables. They are, BOOKS, AUTHOR and LIVRO_AUTOR. To LIVRO_AUTOR has foreign key to the id of BOOKS And AUTHOR. I need to make a…
-
3
votes1
answer2557
viewsRemove spaces via Update
I have a field called titulo, on the table noticias. Unfortunately, due to forgetting the command trim PHP, has several titles with space at the beginning and end of string. How can via SQL (Mysql)…
-
3
votes2
answers939
viewsQuery returns empty using PHP with PDO and MS Sqlserver
I’m migrating a system made in ASP to PHP. However, I’m having trouble making a query using PDO: Search.php class Busca extends Conexao { private $termo; public function setTermo($termo) {…
-
3
votes4
answers8633
viewsSQL query comparing two fields of the same table
I have a table in SQL Server and I’m having trouble making a query. I have a table like this: alunos ra nome serie cod_curso 23 joão 1 EI 23 joão 2 EI 23 joão 3 EI 44 maria 5 EF 44 maria 6 EF 61…
-
3
votes1
answer504
viewsMysql select Random with priorities
I have the following scenario, I have a table and I need to select an order by RAND(). But I would like to put some conditions for example: TABELA ID | NOME | IDADE | GRUPO Dice 1 | Hiago | 20 | 1 2…
-
3
votes3
answers671
viewsHow to make SELECT in more than one bank table?
I have two tables in the database: zip code and users. Can I do a single query to get fields from both tables? Both have idCep. I want to get the address data of the cep table and the name and user…
-
3
votes0
answers100
views -
3
votes2
answers435
viewsConvert SQL syntax from Firebird database to Postgres database at runtime
I have a system developed in Delphi 7 already stable using the Firebird database, and some customers have requested that they can use Postgres as a database in the same system. As with some…
-
3
votes2
answers4180
viewsCreate a script to check if the table has a primary key
I need to create a script to check if a table has primary key, if not, is added to primary key. I found this way to make the script, nas did not understand where it takes the name of this table…
-
3
votes1
answer435
viewsSQL Query Returned Null, Empty for JSON
I’m in trouble!! I have two tables 'user'e 'post' when I use phpmyadmin to make the following query it returns the values as I hope. SELECT usuario.nome, usuario.foto_profile, post.titulo,…
-
3
votes1
answer30
viewsPHP problem with SQL INT
I’m making a form sending the data by AJAX and then insert, so far so good. Only the maximum value of the INT in SQL is 2147483647, and the field I have has at most 11 digits that can go up to…
-
3
votes2
answers912
viewsHow to make sql for a field of a table that is not primary become foreign in another table?
CREATE TABLE PESSOA ( ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, CPF VARCHAR(15) NOT NULL, RG VARCHAR(10) NOT NULL, NOME VARCHAR(128) NOT NULL, DATA_NASCIMENTO DATE, PRIMARY KEY (ID) ) CREATE…
-
3
votes1
answer201
viewsMysql query ranges
I need to assemble a select, where I need to display the results outside a code range. For example: I have code 2 as the beginning and code 6 as the end, how could I not display the codes 3, 4 and 5…