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
answers581
viewsDifference and sum of DATETIME column
I have a table called chamado_processos with the following structure and data As you can see one of the columns of this table called dt_processo is a field DATETIME and the column tp_processo…
-
2
votes2
answers687
viewsQuery sql with multiple java fields
How to do a java sql search that involves multiple arguments? Example: I want to research all people with Angolan nationality, with the Computer Science course and who have two or more years of…
-
2
votes2
answers464
viewsDifference of hours query sql server
I have the following data: 2016-10-13 09:04:00.000 1 2016-10-13 20:33:00.000 4 2016-10-14 09:10:00.000 1 2016-10-14 21:04:00.000 4 2016-10-17 09:04:00.000 1 2016-10-17 19:50:00.000 4 How to know the…
-
2
votes1
answer118
viewsSaturation of Foreign Keys?
After a long time with non-relational database I decided to come back and I came across a strange situation. My app is a simple chat where this chat has sub rooms. I did a little demonstration: I…
-
2
votes2
answers2202
viewsUpdate of several records together with select
I need to do UPDATE with SELECT for several records, today I am with this query: UPDATE banco.ordem SET valor = (SELECT (CEILING((litros * 3.67)*100)/100) AS valor_litros FROM banco.ordem WHERE…
-
2
votes2
answers124
viewsGet more SQL-rated records
I have two tables: comentarios ---id ---comentario ---usuario ---supermercado ---avaliacao supermercado ---id ---nome ---endereco ---admin I want to take the average of ratings from each supermarket…
-
2
votes3
answers1626
viewsIt is possible to collect data of the whole month in postgresql
How do I so that from a specific month I can get all data saved in the database: I think you should spend the year / month as parameter for example variable = "2016/10"; remembering that the data…
-
2
votes1
answer332
viewsQuery with variable date in Mysql returning empty
I need to make a query in Mysql setting 3 variables,when only in the case of right integer,more when I include empty return date ta. Follows my query,what could be doing wrong? SET @tipo = 47; SET…
-
2
votes3
answers1305
viewsList records that are in a table and those that are not in the same table
I have a points table and a users table. At points, I have an ID that references the users table user. What I need to do is return all users who have hit the point, along with those who haven’t hit…
-
2
votes1
answer966
viewsIs there a function to calculate the trend line in PL SQL?
Good morning folks. I need a function to calculate a trend line. I have a query (part of the function): select round(sum(nvl(vl_indice, vl_meta))/12, 2) from ( SELECT SUM (vl_indice) vl_indice, SUM…
-
2
votes2
answers614
viewsHow to make a Select to not show reset result?
I have the select below, which always brings me two lines, one with zero and the other with value: SELECT COUNT(DISTINCT ROMANEIO) ROMANEIO FROM PCN_ROMANEIO_DISTR_ITEM WHERE USUARIO = 'junior'…
-
2
votes1
answer9012
viewsTruncate decimal places arbitrarily with Postgresql
I am making an SQL query using the function sum(). This function sums integers and fractional numbers. The problem is that it returns a double Precision with very large number. How do I limit up to…
-
2
votes1
answer245
viewsSelect to bring specific id record
I wonder how do I bring a specific record of a fk, being that I have the table lodging and the table consumption (with fk codHospedagem). When I select some hosting, I click on the consumption…
-
2
votes2
answers873
viewsDoubt about query in Delphi 7
I have a certain problem when trying to run an update query in my database, Delphi gives error as incorrect syntax, but I could not find the problem. Could someone please help me ? Follows prints:…
-
2
votes2
answers114
viewsReturn vehicles that have all parts in a given table
I have the following question, in my database I have the following tables: | veiculo | | idVeiculo | placa | | peca | | idPeca | nomePeca | | relVeiPec | | idVeiculo | idPeca | | pecaObrig | |…
-
2
votes2
answers1684
viewsSelect with INNER JOIN, bringing fields that have NULL foreign key
I have a table items, requested items, interested (she has self relationship, is used for secretariat, sector and employee, and a table requested), in the table requested I have 3 foreign keys (one…
-
2
votes1
answer289
viewsSql Reader returning null value
I’m running a datareader, however does not return any value, already checked in the table and conditions (where) of select exist in the table. The code goes below: public void consulta() { string…
-
2
votes1
answer70
viewsProblem running eventhandler
I have a class, which is executed under a button, it makes two select in a bank. apos, need to take these two data and make available to use in a second form, I’m trying to make EventHandler,…
-
2
votes1
answer415
views -
2
votes1
answer148
viewsTruncate tables with Cache
I have a hotel table and reserve table. In the reserve table I have the primary key of the hotel table as foreign key. I can’t truncate because there are relationships between keys. How can I? I’ve…
-
2
votes1
answer157
views -
2
votes1
answer104
viewsmysql - row for Gravity Forms columns
Good afternoon, I’m pretty new to database and programming, but I like to move when necessary. I have a table in the database with responses from a form made in wordpress by Gravity Forms that…
-
2
votes2
answers828
viewsHow to differentiate data from two tables with columns of equal names in an SQL request with JOIN?
I combined record of two tables using JOIN, the two tables have some columns with equal names... When extracting data with PHP how will I differentiate ? Example : foreach($dados as $values){ echo…
-
2
votes0
answers544
viewsCreate Mysql Trigger / Stored Procedure to change features of a column
I am trying to create a Trigger/Stored Function for when the user changes the value of a column from 0 to 1 it changes the feature of another column CREATE TABLE `aluno` ( `CPF_ALU` varchar(11) NOT…
-
2
votes1
answer46
viewsSQL Search - Results not duplicated
I am wanting to return a database query without repeated data. The table is called Wps_history and contains the following columns: id user_id adm_user_id type user lancamento data valor saldo reason…
-
2
votes3
answers818
views -
2
votes1
answer344
viewsIs it possible to list the columns used in a SELECT in PHP mysqli?
I have the query SELECT coluna1, coluna2... FROM tabela I wonder if there’s any method in the class mysqli to return these columns that were used in the query, even if the query does not return…
-
2
votes1
answer728
viewsMysql and PHP Dynamic Form - Codeinigter
I need to create a form to create evaluations, with a number of variable questions. For this I created a form that adds questions, as requested; The problem is saving banco de dados this variety of…
-
2
votes1
answer102
viewsPerform action for each line in an SQL search - VB
I wonder if anyone can help me with the following question. In a VB code, I want to perform the search for products in an SQL table. For each product found I would like to add a button in a panel.…
-
2
votes2
answers5887
viewsRemoving part of a string - SQL Server
I have written in a column of the database the name of a file with extension (FILE.txt). I need to show in a SELECT only the FILE instead of FILE.txt Someone knows how to do?
sqlasked 7 years, 10 months ago cmcampos86 207 -
2
votes2
answers2208
viewsSQL to compare hours and minutes when Timestamp in Postgresql
I am trying to compare 2 timestamp fields, which have different dates, ignoring the dates and using only the hour/minute simultaneously, to know, within a same day which of them is bigger. EX:…
-
2
votes1
answer231
viewsHow to calculate the distance between X and Y with Intersection points
In the image above I have mapped the separation positions within the warehouse where I work. I need to calculate how far the person you’re separating travels inside the warehouse. For example if the…
-
2
votes5
answers1818
viewsGroup records per day
I have the following table ID | Início | Fim | Horas 333 | 01/01/2017 | 03/01/2017 | 5 333 | 02/01/2017 | 05/01/2017 | 1 333 | 05/01/2017 | 07/01/2017 | 3 333 | 01/01/2017 | 07/01/2017 | 6 I need a…
-
2
votes1
answer468
viewsHow to use Cascade Delete between two tables?
I have 2 tables: products id name ... products_photos id id_product photo In PHP I will make a DELETE in the Product, and therefore I want to automatically delete ALL photos of the deleted product,…
-
2
votes2
answers602
views -
2
votes2
answers530
viewsHow to make an SQL query with some blank criteria?
I am creating a filter for a database search in a PHP application and obviously I have numerous criteria, but, I have only been able to work with one criterion. Code: select codigo, despesa, data,…
-
2
votes2
answers1623
viewsQuery delete with Join mysql
People I have problem with this query do not know what is wrong: DELETE FROM mdl_forum_discussions WHERE id IN ( SELECT mdl_forum_discussions.id FROM mdl_forum_discussions LEFT JOIN mdl_forum_posts…
-
2
votes5
answers14274
viewspsql command at prompt. (postgresql database)
Good morning, everyone, I’m trying to make a script with extension. bat to make automatic update in the bank,. I am doing as follows to access my bank through windows pronpt. psql -U bank user -w…
-
2
votes1
answer121
viewsMounting an html frame from a php array
The tables: Ciencias (ex: Mathematics, Biology, Chemistry). Areas (e.g.: Algebra I, Biochemistry, Botany, Chemical Bonding). Exercises (e.g.: Water, Algae, Bryophytes, Progressions, Chemical Bonds).…
-
2
votes1
answer582
viewsEnter and search data in the database per user with Laravel
I need to save information in the database per logged-in user. That is, when the user logs in, everything he does will be saved in the database of that login. That is, when user X logs in,…
-
2
votes1
answer274
viewsUpdate column with sort items
Hello, In a given relationship table I have a column that stores the ordering, but due to a problem in the application this column was populated wrong data, as the example |user_log…
-
2
votes1
answer32
viewsSQL - Query Doubt
Guys I have a tremendous doubt, I have these 3 columns need only bring the smallest record if the date is between the between. Example: Case put date 23/12/2015 a 01/01/2016 It is not to bring…
sqlasked 8 years, 4 months ago Daruich Campideli 33 -
2
votes1
answer579
views -
2
votes2
answers805
viewsGroup by by two fields ordered by a third
I have the following data: |--------------------------------------------------------| |USER | ID | DEVICEID | DATE | |--------------------------------------------------------| |7 | 14450 |…
-
2
votes2
answers1410
viewsAlternative to Mysql Workbench
Well, I currently use Mysql Workbench software to do my scripts, wanted a lighter program, someone knows/could pass me some alternatives? I don’t want PHPMYADMIN Note: I develop with PHP - I don’t…
-
2
votes2
answers1333
viewsSet default value SQL Server column
I would like to know how to set an Insert pattern in a column in SQL. Example: CREATE TABLE XPTO( ID INT IDENTITY(1,1), NOME VARCHAR(100) NOT NULL, ATIVO CHAR(1) NOT NULL) In this case, I want to…
-
2
votes1
answer62
viewsLaravel Queries SQL Doubt?
I’m starting with the SQL of Laravel I searched much more I did not get an answer on how to make a AND after a where, follows example code to implement a AND. SQL: UPDATE contas SET valor_titulo =…
-
2
votes1
answer2011
viewsSelect with LIKE argument %
I’m trying to perform a select, using LIKE and defining the argument %: WHERE title LIKE '%computer%' locates all book titles with the word 'computer' anywhere in the book title. source:…
-
2
votes1
answer815
viewsDynamic Image Gallery ASP.Net C#
I have the following Code, It loads the photos into that placeholder. ID="phFotos"> public partial class ImovelDetalhe : System.Web.UI.Page { private ImovelBo _imovelBo; protected void…
-
2
votes2
answers2233
viewsHow to make Join of 2 tables without repeating data?
I have 2 tables, a call SR7010 and another call SR3010. The primary key of the two is the field R7_MAT and R3_MAT. The query I’m trying to execute is this: SELECT R7_FILIAL, R7_MAT, R7_DESCFUN,…