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
votes2
answers293
viewsSort by date in Mysql
I have a table with two fields: dh_premium_expires and score. dh_premium_expires - the date/time the user premium will expire. score - score of the user within the game. On my site I have a list…
-
2
votes1
answer1279
viewsHow to use FOR for INSERT within a function in ORACLE?
I have the following function: FUNCTION PERSISTIR_CR( p_AnoExercicio TB_CONFIGURACAO_EXERCICIO.NUM_EXERCICIO%TYPE ,p_CodCR TB_CESTA_ROTINA.COD_CESTA_ROTINA%TYPE ,p_CodUG TB_CESTA_ROTINA.COD_UG%TYPE…
-
2
votes1
answer118
viewsMysql event to block user with x denunciations
I have a table of complaints where I record the information of users who reported and who they reported id | user | denunciado 1 | userx | userY 2 | userz | userY and so on, now I would like to do a…
-
2
votes1
answer1143
viewsMake an INNER JOIN using IF
I am doing an INNER JOIN of the Combo Table with the Product Combo Table as shown below... SELECT C.SchoolID, C.ComboID, P.Active, P.Name, P.ProductID FROM sales.Combo AS C INNER JOIN commons.Stock…
-
2
votes1
answer168
viewsSQL does not work on another device after publishing to the web
Because my page cannot run queries to the bank when it is published on the web and being used from other devices (computers and smartphone networked)? If I use it from the computer itself (server),…
-
2
votes3
answers22309
viewsIF condition inside a WHERE - ORACLE PL/SQL
See below for details of the problem in question: CREATE OR REPLACE PROCEDURE NOVODIA.PRC_PACIENTES_INATIVOS_95 ( --PARAMETROS IN_CPF IN VARCHAR2, IN_CARTAO IN VARCHAR2, OUT_CURSOR OUT SYS_REFCURSOR…
-
2
votes1
answer593
viewsHow to use LEAD and LAG using a condition
My question is, if I can use LAG and LEAD, using a condition in the query, for example: I have the spine cep.. I want to take the value of the next row, and the value of the previous row of that…
-
2
votes2
answers2139
views -
2
votes2
answers2389
viewsStored Procedure with output parameter being the Id of the last insertion. C#
Hello, I’m performing an insert in a table, but I need it to return the ID you just entered. I searched on the command OUTPUT but I couldn’t solve my problem. I need to do all this using procedures,…
-
2
votes1
answer2663
viewsSearch method involving Java and SQL Server
How to do a java search by passing an (SQL) attribute as parameter? I decided to type a sketch of Cod: MAIN static private void PesquisarUsuario(Connection con) throws SQLException { int cpf;…
-
2
votes1
answer175
views -
2
votes2
answers513
viewsHow to put between within a code query?
I have the following consultation and I would like to put in the clause Where the condition of being within a certain period. public static DataTable stCloseCaseAll(int schoolId, string dataInicial,…
-
2
votes1
answer728
viewsSelect column type that comes in a SELECT
Hello, my question is this:: I have a Select in Sqlserver of two tables with Inner Join, they return me a set of 5 columns. I would like to know how to list the type of these columns. I know you…
-
2
votes1
answer289
viewsExclusion involving Java and SQL
The program I’m doing requires a deletion of users from the bank! In the code I determine: Menu: static private void Excluir(Connection con) throws SQLException { String cpf; Scanner s = new…
-
2
votes3
answers1143
viewsLoop output within another loop with SQL and PHP
I have these values in my SQL database, I want an output this way and this file in the browser using PHP Database structure with the values I want on output My attempts, although it does not help…
-
2
votes2
answers192
viewsRemove from account when value is 0
I have the following query: SELECT ROUND((( notaAmbiente + notaApresentacaoDasPizzas + notaQualidadeDosProdutos + notaVariedadeDeSabores + notaAtendimentoNaLoja + notaAtendimentoNoTel +…
-
2
votes3
answers28024
viewsSUBSELECT vs. INNER JOIN
Is there any recommendation on which of the two is preferable in terms of performance? SELECT funcionarios.nome FROM funcionarios INNER JOIN empresas ON empresas.id = funcionarios.empresa_id WHERE…
-
2
votes1
answer659
viewsShow null results through LEFT JOIN with Linq!
I have an SQL query: SELECT A.Codplano, A.Secao, A.Setor,A.Subsetor,A.Contato, ISNULL(B.Subord,'NÃO LANÇADA')AS Situacao FROM vwPLANODIN A LEFT JOIN LANCADA B ON A.Codplano = B.Subord and B.Data =…
-
2
votes1
answer85
viewsTrack SQL output in Java
My java application for web gives several times the error of SQL Syntax, but only indicates a snippet of the SQL script that gives error. Is there any way I can see the full script that was "played"…
-
2
votes3
answers42978
viewsHow to make a select with multiple `Where field like '%'` in C#
select below even works, but it searches all fields and would like the idaluno, nomealuno and cpf were searched and ordered by idaluno SELECT…
-
2
votes2
answers210
viewsQuery performance with date range
Assuming I have a database table with 10000 data and each record is registered with dates between 2013 and 2014. A query like this: SELECT CAMPO_DATA FROM TABELA WHERE CAMPO_DATA BETWEEN…
-
2
votes1
answer788
viewsRow sorting in a table with SQL SERVER
I have a table (Customer) example: ID Nome Order 1 Joao 1 2 Ana 2 3 Marta 3 4 Joana 4 The goal is to sort the contents as follows: I get the ID (@ID) from the position to change and the new position…
-
2
votes1
answer142
viewsList grouped and filtered data
I’m performing a query in PUBS, the database that is used in MSDN tutorials for SQL Server, and I can’t find a way to do it. The two tables I use are the Publishers and the Titles who have the…
-
2
votes1
answer569
views -
2
votes2
answers135
viewsHow do I sum up the 2-interval difference in Postgresql?
I need to sum up all the gap differences that meet the Where condition. There is only one however, if there is no end_date on this line, I need to take the current time and do the calculation with…
-
2
votes1
answer847
viewserror in mysqli query
Person, how I fix this my code, it is giving error: <?php //IMPRIME TODOS OS VALORES DO BANCO CADASTRO $servidor = "localhost"; $usuario = "root"; $senha = "admin"; $banco = "cadastro";…
-
2
votes1
answer950
viewsReturn total of each order with Mysql?
Imagine I have a table pedidos with the following fields: And that I have two other tables (pedido_a, pedido_b) of two different types of applications as the examples below: Each item in the table…
-
2
votes1
answer702
viewsCommand to display a record limit in a table
Supposing that a database have a table locacoes, which SQL command would display between the tenth and twentieth record of this table, ordered by the field titulo?…
-
2
votes2
answers174
viewsWhat SQL server command to list the user’s transaction Isolation level
Is there any command I can run on sql server to list the user’s Isolation level transaction?
-
2
votes1
answer506
viewsWrite Listview in SQL Database using Entity Framework and C#
I am developing a sales desktop application using C# and Entity Framework and I am having doubts about recording the items entered in ListView in the SQL database. How to save inserted items to…
-
2
votes1
answer118
viewsHow to search and show data
Well. I need to do a search in one table and through this search pull the data from another. But I ended up getting lost in logic ... Example of what I’m doing: The user informs the data he wants:…
-
2
votes3
answers162
viewsCreate tables randomly
My question is this:: I have a table containing 25 records of people’s names. But I need to divide it into 5 groups of 5 people randomly. Being a table 'Group A' with 5 people, another table 'Group…
-
2
votes1
answer318
viewsUse Inner Join with Bindingsource
I’m trying to make a query in an access bank using inner join along with BindingSource, this Binding will send the data to a Datagridview. However, when the data is loaded into the grid, the…
-
2
votes4
answers2214
viewsSQL query return total of days in a month on two dates
I have the following tables: staff: id_funcionario other information... historical: id_funcionario data_input dating I tried some querys but I couldn’t get what I wanted. What I need is, after the…
-
2
votes2
answers1876
viewsHow to use sum with condition relative to another field
I have a table of evaluations in the format TABLE AVALIACAO (id_avaliacao, id_pessoa, concluida, segunda_avaliacao) and another table that records the notes TABLE NOTA (id_nota, id_avaliacao,…
-
2
votes1
answer275
viewsCreate a conditional using the relational model
I’m trying to create a conditional "or" just using the relational paradigm: Having the tables pessoa, cliente, funcionario and considering that a person may be a client or an employee (a 1:1 ratio,…
-
2
votes1
answer2175
viewsIs there any way to recover data from a Mysql database?
I gave a delete on some files from table, it has some way to recover? I heard about the "flashback", but the little I researched is only for oracle.
-
2
votes1
answer180
viewsIs it wrong to leave a FK inside the table that gives rise to PK?
It’s wrong to do this on a bank table? Let me quote an example: We have the Customer: Google And in it we have the unit: Google Brasil Then we have the following example table: Table Client Id |…
-
2
votes2
answers455
viewsQuestions about database and Android
I am developing a project for college that is a multiplayer game for Android of questions and answers (style Asked). In the development of the game, I need to create a database to store the…
-
2
votes1
answer981
viewsSQL query does not work when it has accents
I have in my database a category defined as LAND/AREAS that when making the following SQL query does not return any result of the existing 18. SELECT * FROM immovable WHERE 1=1 AND CATEGORY IN…
-
2
votes1
answer4268
viewsHow to select only the days of the week?
How do I take only weekdays, excluding weekends, using SQL? I need to notify the customer about some debt, and if it is Friday I can’t charge it because it will start the weekend, he will have…
sqlasked 10 years ago Wesley Costa 159 -
2
votes1
answer84
viewsHow to get the Foreign Keys creation script from the entire database? SQL Server 2008
I wonder if there is a command that returns the script of creating the Foreign Keys in SQL server, as well as the command sp_helptext returns the script of creating views and stored procedures for…
-
2
votes1
answer109
viewsBackup Database Sqlserver
I know that to perform a backup in SQL Server just use: BACKUP DATABASE nome_database TO DISK = 'endereco\nome__arquivo.bak' But does anyone know how to backup all Databases together? Each one in a…
-
2
votes1
answer230
viewsHow to search for multiple order independent terms?
my scenario and the following, I have an input where the user puts the term and clicks on search EX: car horizon [ENTER] however you are listing the result of the separate words EX: 3 results found…
-
2
votes1
answer211
viewsIs there a command to change a user-created type in Sql Server?
I created a type in my Sql Server database: CREATE TYPE [dtNumero] FROM [numeric](18, 5) NOT NULL Is there a command for you to change this type, for example the accuracy?…
-
2
votes1
answer2608
viewsAssign execute command to a variable
I need the return of the execute command to be assigned to the @PAGO variable because I will insert it into a temporary table only what returns is the script and not the value. DECLARE…
-
2
votes1
answer390
viewsHow to get the record total of a table
I need to know how many records there are within my table and add the total find into one variable. I’m doing it this way but it doesn’t work: <?php $w_querybusca = "SELECT * FROM Elem_matr;";…
-
2
votes1
answer628
viewsGenerate database backup via application
In my project I connect to the database. Is there any way I can do the backup from my database via Asp.net mvc 5 and keep that backup in a directory, either at the project root or in a folder in a…
-
2
votes1
answer46
viewsTotal sum of values of all dates
How do I sum X values of a specific date and compare if the summed value is greater than 100? /* Data das consultas, e para cada data o somatório total dos valores, desde que este total seja maior…
-
2
votes1
answer557
viewsHow do I insert any file extension into an SQL database?
I always worked attaching only images in my BDD tables, I remember that converted to MemoryStream and then to Byte and inserted... But I need to insert any kind of file extension in my database.…