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
-
2
votes1
answer42
viewsReducing line quantities in a query
In my system I have 3 tables: -Table Film - a film features several artists -Artista Table -Table Participates in film - this table, contains the ID’s of the movie and artist table. When I want to…
-
2
votes1
answer411
viewsHow to do a query in sql that returns data from a table when the data is empty?
Well, I created a table called installments, that when the customer pays it is inserted 'PAID' in the column situation, and when not paid it remains blank. I wanted to fetch the information from…
-
2
votes2
answers41
viewsLogin form returning error!
I have a login form that returns the following ERROR: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near 'as valor…
-
2
votes1
answer158
viewsSQL - How to make multiple Inserts in a table with the result of a SELECT * of another table in a query
Hello, I would like to know how to make several Inserts in a table with the result of a SELECT of all id of another table table that are not as foreign key in the first table. I already have the…
-
2
votes1
answer565
viewsDisplay BLOB text
I have the following problem, in a report I need to display a field of the request that is as BLOB. And when I run the search it returns a strange code instead of the field information. $sql =…
-
2
votes1
answer46
viewsHow to print the selected database ID?
Is there a function to take information from a specific ID of my database and print with domf? My code: $id = "30"; $result_usuario = "SELECT * FROM cadastro WHERE id = '$id' LIMIT 1";…
-
2
votes4
answers3710
viewsDoubt with month and year extraction in Postgresql date
I am using a select command where I take the month and year of the date as follows: extract(year from D.dt_ficha) + extract(month from D.dt_ficha) Only instead of showing up like this: 201711…
-
2
votes2
answers176
viewsSelect a certain amount of data for each status type
Billy Jow here! On my table historical I have a field status that can assume four possible values: 'EVALUATE', 'FAILURE', 'REEVALUATE', 'SUCCESS' I wish to select 20 records from each status where…
-
2
votes1
answer1327
viewsHow to do GROUP BY in UNION ALL?
I have the following code: String select1 = @"SELECT CODIGOB, DESCRICAO, QUANTIDADE FROM " + path + @"\IVENDA.DBF WHERE DATA BETWEEN {^" + datainicial + "} AND {^" + datafinal + @"} "; String…
-
2
votes1
answer468
viewsHow to declare "nullable" parameters in an Oracle database?
I need my process to accept null values in some parameters of type Number. How do I do this in PL/SQL? Currently: PROCEDURE SP_EDITAR_QUADRO( P_IDQUADRO IN NUMBER, P_IDFUNC IN NUMBER, P_IDTRAB IN…
-
2
votes2
answers81
viewsHow to get the value of one table depending on the maximum value of another?
I have the following code that gives me a table like the picture, but my doubt is how do I only get the name and only the name of the one that has the highest health value that will be gasoline? It…
-
2
votes1
answer200
viewsSQL - Search for the names of patients who had more appointments in January 2016
Hello, I would like to know how to do this consultation: "Find the name of the patients who had more appointments in January 2016". select * from PACIENTES select * from CONSULTAS These are the…
-
2
votes2
answers229
viewsComparing a subquery with another subquery
I have two tables, table A and table B, each with a column called text. Both tables have equal records to some extent, up to the character '='. What I want to do is a SELECT of all records in table…
-
2
votes1
answer95
viewsHow to remove keywords between { } keys in the Mysql field?
I have a table that contains a field with some values between keys, how do I delete the chaves and the valores that are within them? Example: cod | Movimento | 01 | Prazos {aguardando} | Prazos…
-
2
votes1
answer849
viewsDelete a record from the database when the deadline is passed
How can I automatically delete a record from the MYSQL database when it reaches a deadline? remembering I am using a data_termino attribute of type Date
-
2
votes1
answer197
viewsSQL SERVER odd line queries
I need to create query script that returns from the table below only its odd lines, ordered upwards: DECLARE @table TABLE (coluna1 varchar(50)) INSERT INTO @table VALUES…
-
2
votes1
answer533
viewsSQL Select highest value item
I’m using the Northwind database, and I want to select the category that has the largest number of registered items. I was able to list the category ID and the number of products it has with the…
-
2
votes1
answer33
viewsSqldatareader Incompatible Databindtable does not implement Ienumerable
I have a problem showing the data of a column on sqlserver, to insert as x and y in my Chart in Asp.net. The problem is this, it seems the method (DataBindTable) is waiting for IEnumerable but my…
-
2
votes1
answer65
viewsHow to make a select that brings the data registered in a given week?
I intend to list all the data registered in a given week, someone can help me? I did something similar to the example below and it doesn’t work. public List<View_Venda> Venda_Semanais() {…
-
2
votes3
answers58
viewsSQL Query - Doubt Condition Dates
Guys, good afternoon! I’m having difficulty in the consultation below. I want you to bring all the tasks only when their salary (tarexpiration field) is equal to the month after the opening date…
-
2
votes2
answers342
viewsMask SQL Select return
I’m using the following SELECT to return the Ids one-table. SELECT id, duracao_sessao FROM usuario For ID 1 I want the text "Object" For ID 2 I want the text "Class" For ID 3 I want the text…
-
2
votes2
answers7816
viewsConsult in all tables of the database
It is possible to make a query in all tables containing the same column their respective values? For example, I have the Bank called SGE, it has 230 tables, and all these tables have the column…
-
2
votes2
answers347
viewsError while calling Activity
main activity import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import…
-
2
votes1
answer26028
viewsCompare NULL using CASE SQL
I have to recover 2 fields in this query (number of projects and the management that runs such a project). This query will be used to generate a report in JASPER and it does not display field with…
-
2
votes3
answers1806
viewsSQL searching records from a Date and Time
I have the following SQL: select * from tb_valores where DATA >= '14/12/17' and HORA >= '16:34:00') I would like to bring all records from that date and time. The problem is that if I have…
-
2
votes1
answer79
viewsPick all levels of product categories
I have a question. I have a table of categories: CREATE TABLE `categorias` ( `id` int(10) UNSIGNED NOT NULL, `parent_id` int(10) DEFAULT NULL, `lft` int(10) DEFAULT NULL, `rght` int(10) DEFAULT…
-
2
votes1
answer399
viewsHTML & PHP - HTML code simply not read
I have following code on the part of PHP does not present any error, the page appears blank and does not show the HTML code. <?php include("config.php"); if($_GET['key'] &&…
-
2
votes2
answers63
viewsPHP errors/warnings parameter 1 & 2
In my PHP code appear the following "warnings": Warning: mysqli_query() expects Parameter 2 to be string, Object Given in line 8 Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result,…
-
2
votes4
answers2082
viewsCompare a table field with another table
I am trying to create a query in SQL Server to know if the city that was filled in at the time of registration that the person did, is equal to a city field of another table that already has all the…
-
2
votes0
answers64
viewsPHP - password reset code problems
I am trying to create a link that is sent to the user so that I can reset the password: I have the following code that sends the code to the user: <?php include("config.php");…
-
2
votes1
answer668
viewsexclude column of select *
I have an api that returns the data of the user in json, but wanted to return all data except the password, would it have any way without being select in all fields except the password? I’m doing so…
-
2
votes1
answer248
viewsFetch ip via sql
Does anyone know if there is a way for me to search via sql (Firebird) all ips that are using a Table or Views? I am trying to update a view, but am trying the following error: This operation is not…
-
2
votes2
answers1580
viewsImport CSV and convert date in dd/mm/yyyy format to yyyy-mm-dd
I’m a complete beginner in programming, both in Python and Sql, so I have some questions that may seem basic. I get a file. CSV that comes a lot of information not compatible with Sql so always have…
-
2
votes2
answers625
viewsQuery SQL - CASE with LEFT JOIN
I need to create a query that returns all active students and their grades for each subject. If the student has no grade for a particular subject should be returned the student, the subject and in…
-
2
votes1
answer1411
viewsSelect with Inner June too slow
I have a problem where select is bringing the right result, but taking too long. Follow select : SELECT c.cod_paciente, p.nome, i.valor, i.quantidade, d.convenio, c.cod_conta FROM caddadosclinico d…
-
2
votes2
answers273
viewsHow to order day data in SQL with Unix Time Stamp (PHP)
Hello I’m with a doubt here, I’m creating a code to get how many users have logged on to my site today, but I saved the last date he logged on with Unix Time Stamp. I’m only able to get users who…
-
2
votes1
answer39
viewsCopy of Oracle materials structure
We have the following material registration structure: Table Pk FK Filial Descricao material Group Cod_grupo 1 - 1 Materiais de escritório 2 - 1 EPIS 3 - 1 impressos Subgroup Cod_Subgrupo Cod_grupo…
-
2
votes1
answer674
viewsAssign a variable a Dynamic Date?
My goal is to create a SQL Server, which has by default two variables, one with the initial date of (hoje - 3 anos) and a final date equal to hoje. I already use for other operations (for example a…
-
2
votes1
answer105
viewsHow can I compare the data in the same column?
"Create a function (named fn_bo_varios_states) that takes as parameter the code (INTEGER) of a victim and return (TRUE or FALSE) if she has already registered reports of occurrence in more than one…
-
2
votes2
answers45
viewsError in SQL output
Guys, here’s the thing, I’m having to do a select in a bank, where I should look for values that exist between two dates, and that have a specific user. I made the select so: SELECT * FROM `tabela`…
-
2
votes1
answer222
viewsCASE WITH IN does not work
I’m willing to do this search below: DECLARE @codccu VARCHAR(10); SET @CodCcu = '63' SELECT E.codepi, E.numcad, Max(E.datent) AS ENTREGA, Max(E.datent) + P.diaval AS VALIDADE, CASE WHEN…
-
2
votes2
answers548
viewsRows in Columns (SQL)
I’ve been thinking for a few days about how to make a select less verbose, turning rows into columns. Today I have it that way: (SELECT s.code_sample FROM app_sample s WHERE s.id_analysis = a.id AND…
-
2
votes1
answer1525
viewsIs it possible to search a data in the database without knowing which table it is in?
I have a banco de dados very large and it is impossible to build a SELECT * FROM for each table and locate the data I need. It is a texto especifico ('with as parameter 23') I’ve searched every way…
-
2
votes1
answer2546
viewsHow do I know if a column exists in an Oracle table?
I’m trying to add a new column to an Oracle table, and I want to know if it already exists or not. I’ve tried something like this: IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE…
-
2
votes3
answers1756
viewsHow to declare a cursor variable in PL-SQL?
I have a course: Cursor Pessoa is Select nomeFuncionario From empresa; -- Variaveis para uso da rotina variavel How would the variable ?
-
2
votes1
answer270
viewsQuery the Database in Android
I would like a help from you to check what is wrong with this consultation: int raioKm = 10; String latitude = "CONVERT(" + "NUMERIC(10,7), " + "SUBSTRING(localizacao, 0, CHARINDEX(localizacao, ','…
-
2
votes1
answer355
viewsGet all data with the same id without knowing the id
I have a table in the database with information that have the same ID, as if they were a set, I would like to get all the information with this ID, but I don’t have it, and I’m using a LIKE to…
-
2
votes2
answers9062
viewsConcatenate text to an existing SQL column
I got the following SQL: UPDATE tabela SET peso = peso "KG" I need to add to the weight field, the tag KG, But if I do it the way I put it, it doesn’t work. How could I do it?…
sqlasked 6 years, 9 months ago Sr. André Baill 6,946 -
2
votes1
answer64
viewsDoubt in conversion of rows into columns Sql Server 2012
I turned rows into columns and need to improve this query by adding another row in column: This is the query: --****************************EMPRESA******************************…
-
2
votes2
answers117
viewsReturn records that total desired value
I have a table in this format, with more N values and N suppliers, approximately 100 thousand records, and I need to do through a query or a plpgsql function a way to get all the release numbers num…