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
answer246
viewsWhat kind of conversion does the pre-compiler of a DBMS with the SQL language?
The compiler of a DBMS handles commands written in SQL. Assuming I’m using Mysql. What would be done with the command: select * from client; What type of conversion does the pre-compiler of a DBMS…
-
1
votes1
answer1776
viewsImporting a very large . sql file
I have a file about 192.2 MB in size. I tried to import it through Phpmyadmin, but he complains that the file is too big. I searched the internet for a possible solution to the case, and I saw that…
-
1
votes2
answers606
viewsSort result using CASE and BETWEEN
In the first code just below, I can list the freight price of the table transport via the band cep and peso, however I am having a problem, I need to sort the result according to how cep sent,…
-
1
votes1
answer3169
viewsHow do I connect to the database via [Wordpress] to query?
Well, I have a call jQuery Ajax in the header.php of my theme that is entering a file PHP at the root of my Wordpress and return me the echo test. I need this file to query the banco de dados and…
-
1
votes2
answers619
viewsHow to get data from two tables in the same column?
I have two tables in the database: Tabela1 Id Nome Sexo 1 NomeA Macho 2 NomeC Fêmea Tabela2 Id Nome Sexo 1 NomeB Macho 2 NomeD Fêmea I would like to have the following result: Id Nome Sexo Tabela 1…
-
1
votes0
answers108
viewsProblem with aggregation function, using Hibernate Createquery
In a Package, a fkEmbaling refers to the 'father', the larger package. EX: Let’s say that 10 A packs fit inside a B package. A packaging record A will have in its fkEmballing the packaging B in…
-
1
votes1
answer3034
viewsHow to select by taking the record that has the maximum value of a field?
I am doing a select that is seeking records that meet some conditions and then should take from them only the record that has the maximum value of a given field. It’s like this: SELECT…
-
1
votes1
answer321
viewsFrom CTE in SQL to relational algebra
How to pass a CTE in SQL for relational algebra, for example: with publicacao_cte (nome,nr_publicacoes) AS ( select candidato.nome, Count(1) as nr_publicacoes from candidato, cv, ficha_inscricao,…
-
1
votes1
answer1194
viewsCreate Mysql Trigger increment/decrement attribute
I have the following tables -> app(id_app, nome_app) -> category(id_category, nome_category, total_apps) -> app_category(id_app_fk, id_category_fk) What I want to do is this, that whenever…
-
1
votes2
answers172
viewsQuery Performance in Mysql
I have in my form the option to perform a search for Rg or Cpf. So I got the question about the performance of the query using the following code: SELECT * FROM DADOSPESSOAIS WHERE (Rg = @Rg OR Cpf…
-
1
votes2
answers386
viewsJoin commands (Join) in SQL
I have some doubts about the commands inner join, left join, right join and full join, I don’t know if it’s just the join that makes the junctions between the tables, but along with it comes these…
-
1
votes1
answer622
viewsError Case and Group by - Oracle SQL Developer
Hello, I’m trying to group the results of a query with case as follows: select case when sal BETWEEN 0 and 100000 then 1 when sal BETWEEN 100001 and 200000 then 2 when sal BETWEEN 200001 and 300000…
-
1
votes0
answers51
viewsCustom search Fields and tags in Wordpress with slow results
I have a Wordpress site that holds custom Fields related to "Photo Albuns", I am now creating a search engine for such. The problem is that because he uses Tags in his albums and custom_fields in…
-
1
votes1
answer41
viewshow to make a Join Inner picking up the description
my tables: agencias (id, nome_agencia, ads -> FK pra tabela de baixo) ads (id, nome, agencia -> essa é FK pra tabela anterior) the problem is this: each agency will have an ads in the ads has…
-
1
votes1
answer1088
viewssearch product/property with autocomplete and fill content dynamically with php and mysql
I am developing a quick search field with jquery ui, php and mysql autocomplete. The autocomplete works perfectly however, I would like to do otherwise. When the user starts typing in the field is…
-
1
votes0
answers227
viewsMaking Mysql UPDATE in DB database according to Mysql SELECT in DB2 database
I need to update a field (office) of a table (investor) of the database (B2c) on my website. However, this UPDATE will depend on a SELECT query that is made in another database of another site (both…
-
1
votes2
answers4197
viewsFirebird - Select with date less than 10 days
I searched but did not understand how to use the function DATEDIFF() in the FIREBIRD what I need is for the query to return me records with dates up to 10 previous days from the date current. Obs:…
-
1
votes2
answers6427
viewsExport data from Firebird
I have a client registration program linked to Firebird, but I will not use this program anymore and I need the data. Could I take the database.fbd file, which I’m afraid is all the entries and…
-
1
votes1
answer48
viewsHow to re-assign the ID colunda again?
I have a table for example | ID | NOME | | 2 | Ana | | 7 | João | | 15 | Vera | The ID column is ID int NOT NULL AUTO_INCREMENT, What I need to get? I intend for the column to stay | ID | NOME | | 1…
-
1
votes1
answer1546
viewsSQL query grouping by age group
Hello, I need a way to make an sql query that brings me the amount of male and female people. OBS: I have two tables where the first one is registered in it I have the sex column and another table…
-
1
votes1
answer782
viewsOrder by SQL Server under Procedure
Hello, I have the following situation: I need to select the amount of care of people of some age groups and of those who are male and female. I have the following tables: cadastro (id, natendimento,…
-
1
votes3
answers74
viewsSQL Query autodelete
As I could make a self-deletable query in SQL, I would like to query such value and then delete in just one query. EX: select * from usuarios where nome=lucas that is to receive the search and…
-
1
votes2
answers277
viewsFormat select output
I have a problem to format a column in gridview, this column takes three values from the concatenated database, utlimo value can be null, if null has with not present the last trace that separates…
-
1
votes1
answer89
viewsSql query bringing the products that are with zero balance
I have the tables : Produto Departamento ========= ======== Id_Prod id_Departamento Descricao Descricao Produto_Departamento ===================== id_Prod Id_Departamento Saldo Having the following…
sqlasked 8 years, 10 months ago Mauricio Chi Wan Cheung 11 -
1
votes2
answers71
viewsPassing value of a VARCHAR variable in the WHERE IN command
good night. I have the following example process CREATE PROCEDURE sp_listaFuncionarios @nome_dept varchar(50) as SELECT * FROM Funcionarios WHERE nome_departamento IN (@nome_dept) If during the…
-
1
votes1
answer395
viewsTo delimit a txt file, that is, the line size should be 700 characters for all subsequent lines
I created a routine that reads some tables and generates lines as read. It’s all right at first. but the generated txt exceeds the size of the fields, for example, a field has size 10 and another…
-
1
votes1
answer271
viewsSTORED PROCEDURE
I have 2 procedures and I wanted to call the trial sp_is_temporada in the past sp_calcula_curso, where the value of the sp_is_temporada return will be used in procecure sp_calcula_curso, and the…
-
1
votes1
answer364
viewsMYSQL - FK ERROR
Hi, could you help me? I am trying to add the FK in the employees table, only it is giving this error OBS I am creating the other tables before the employees 20:29:15 CREATE TABLE Funcionarios( id…
-
1
votes1
answer123
viewsStored Procedure loop
I built this project, it makes the query inside the cursor right, but when I select SPA_VALOR_ACOMODACAO, it returns the 0, which was set before the loop_duracao. Looks like it’s not getting into…
-
1
votes1
answer90
viewsHow to register each new relationship between two entities
Considering a scenario where a member has a account, personal profile, academic profile and may vary between status (between pre-defined status: teacher, student and collaborator) within the system.…
-
1
votes2
answers268
viewsHow to mount an SQL to display grouped content per month?
I need to mount an SQL to group information per month within Bootstrap formatted columns. Come on: <div class="container"> <div class="row"> <div class="col-md-3"> <h2…
-
1
votes2
answers223
viewsSELECT sort by the quantity of another SELECT
I have two tables in MYSQL: account: id apelido_usuario 1 caio 2 manoel 3 josé product idconta status 1 3 1 3 1 1 2 3 3 2 I made a SELECT like this: SELECT * FROM conta WHERE apelido_usuario…
-
1
votes1
answer766
viewsUpdate with Select
I’m new to the forum and SQL. I use the Mysql Workbench DBMS to try to learn the syntax. Consulting a tutorial site, went to perform an update using a select, follows command line: update actor set…
-
1
votes1
answer2251
viewsList AD groups via a query
I’m looking for a direct query to Adctive Directory. I need to know which groups Views are linked, the same goes for users. The structure, for you to understand better: is created a group where is…
-
1
votes1
answer30
viewsDoubt in SQL Query
Guys I have the following table: --- mensagens id usuario_envia usuario_recebe texto data_envio But I want to list only the "Conversations", for example, I want you to list the messages grouping…
-
1
votes2
answers141
viewsDoubt about mysql - Save, Update and Show data
Talk guys! I have a question. I created a static page that will show some data. For example, I want to show you the live score of a specific football game. I thought of creating a static page with:…
-
1
votes5
answers100
viewsCopy a word from a column to the end
I have several records in sql for example almedia,jose costa santos and I want to change the value to: jose costa santos almeida In other words, I want to take the last name at the beginning (before…
-
1
votes2
answers54
viewshierarchyid, remove children from one node and assign to another node
I have a user table, with the use of hierarchyid, I need to remove all Subordinate Users from User 1 and assign them to User 2. SELECT US.cd_usuario ,(SELECT cd_usuario FROM USUARIO USR WHERE…
-
1
votes1
answer50
viewsSQL query doubt
Guys , I saw the following expression in a sql video: (union select 1,2,3 ) What does it mean ? video link: https://www.youtube.com/watch?v=N0zAChmZIZU…
-
1
votes1
answer117
viewsReturn Wordpress Post
I have the following script that returns me the status and the amount of posts you have in this state, now I would like to display these posts, someone knows some solution? <?php $query=" SELECT…
-
1
votes2
answers462
viewsSearch without returning PDO data
My variable is being passed but the filter process is always not returning anything. try { $keyword = trim($_GET["keyword"]); if (!empty($keyword)) { $sql = "SELECT * FROM noticias WHERE titulo LIKE…
-
1
votes0
answers31
viewsProblems with data type
My website is popping up like this http://www.adota-me.tk/anuncio.php?id_anuncio=1454792030 With some strange characters. I’ll tell you everything I put. In php this:…
-
1
votes2
answers210
viewsGet older value from another table
need to create a query that returns the oldest stock of each product within a specified period: Tabela Produtos: ID DESCRICAO 1 TOMATE 2 ABACAXI Tabela Estoque: DATA HORA PRODUTO ESTOQUE 01/01/2015…
-
1
votes1
answer57
viewsQuery Question - Group Data
I have a question about how to group the data as follows. I have a table called ALUNO_LEGADO, as below: I need to put together a query to get all the students who failed every subject enrolled in a…
-
1
votes1
answer93
viewsDoubt User table and Friend table
Eae guys, I need help, I’m a beginner in java, and I’m doing a college job where it’s going to be a mini social network, at the beginning we will make user registration, within the class Beans, user…
-
1
votes2
answers184
viewsHow to interrupt the database query using time out in Hibernate?
I am developing an application that queries a gigantic database, so I would like to maintain the integrity of this allowing Hibernate to query up to 30 seconds. Faced with this problem, what would…
-
1
votes1
answer1005
viewsRunning 2 queries at once is possible?
I need to change all fields of a table and only insert another result into a row. I am using the following code $Nid = intval($_GET['Nid']); $sql = "UPDATE * FROM programacao SET status='offline'…
-
1
votes1
answer441
viewsDecimal value with 5 decimal places in sql server
I’m developing an application (Asp.NET MVC 5.2.3.0, EF 6.1.3 e SQL Server 2012), the database has a table with the field decimal(6, 5), when I save a value in this field -2,56478 for example in the…
-
1
votes1
answer4404
viewsMysql: Pivot (p rows/ columns) columns with the result of a query dynamically
I have two sets of tables below: 1: 2: I created a query that brings the results of the two tables using Union: Select tbprojeto.projNome As Projeto, tbindp.indPNome As `Tipo(Ind/Idx)`,…
-
1
votes1
answer70
viewsProblem When printing an SQL query on the PHP page
I have an Sql query and my code is only printed the first line of the query, Does anyone have any idea what might be my problem ? ERROR: Warning: mysql_fetch_assoc() expects Parameter 1 to be…