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
votes2
answers42
viewsForeign SQL key
I have two tables in SQL and I need to perform a search. The tables and fields are: Employees: code and employee name Team: 'codigoEquipe' and 'functionRegistered', where 'functionRegistered' is…
-
1
votes3
answers55
viewsRelationship between tables varying according to value
I have a chart that can record the id reference (FK) in more than one column. I need to make a select that links to the first reference column and if it is null, make the link through the second…
sqlasked 6 years, 11 months ago Régis Neis 13 -
1
votes2
answers67
viewsTrying to search with specific id in a period
I’m trying to get a car specific between dates, because it works in periods, more need to get the element ID, I do not know if I would have to apply some other query or include in it, the bank I use…
-
1
votes1
answer133
viewsUse TIMESTAMPDIFF in table creation
I am adding mysql support to my program, currently only works with sql server, so I came across a problem with mysql. Table sql server: CREATE TABLE [dbo].[login_user]( [idx] [int] IDENTITY(1,1) NOT…
-
1
votes1
answer1299
viewsCreate Trigger after update in the table itself and in another table
First I have a table: create table alecrim( id_alecrim int not null auto_increment, sem_epi int not null unique, p1 smallint, p2 smallint, p3 smallint, p4 smallint, p5 smallint, p6 smallint, p7…
-
1
votes1
answer712
viewsHow to bring information from the database and insert it into a table (bootstrap)
Good afternoon! I have been trying to bring information from the database user and insert it into a table that follows the bootstrap syntax. But because of the complexity of tags I end up curling up…
-
1
votes1
answer1060
viewsDOUBT ABOUT SUBSELECT IN FIREBIRD
Hello, good evening! I have a table that involves the input and output part of a box, an example of this is: no day 01/01/2018 the user reported that entered R $ 200,00 in the company’s vault, the…
-
1
votes1
answer164
viewsSelect with two fields like Fks from the same table
I’d like to know how to ride a select in Oracle to perform the departure of the names of the teams that participated in a game, using the structure below: Follow the code to create the table: Code…
-
1
votes1
answer46
viewsProblem when trying to query with PHP and MYSQL
I’m trying to make a query directly in the PHP file where it creates the connection to the database. This query will create my table. The problem is that I am trying to reference the connection…
-
1
votes2
answers56
viewsQuery SQL Server - Union
Guys, the following query below through the Union is bringing in as follows. Consultor UsuID Tentativa 1 Abertos Gabriela Sousa 95093 17 Gabriela Sousa 95093 32 But I want to bring it this way:…
-
1
votes2
answers48
viewsI’m having trouble creating a database and relating 3 tables
I’m having difficulty creating a database and relating 3 tables : return the name and surname of the customer, his neighborhood, and the values of his movements,the date ordering the movements for…
-
1
votes2
answers1406
viewsSQL Server - Changing information in a text field (REPLACE does not work)
Hello guys. I have a table with a TEXT field. I need to change information within this text field only that I am not getting. The REPLACE function works in a varchar field, but does not work within…
-
1
votes1
answer2907
viewsSelect to count quantity per column
How I make a select that returns the amount of equipment repeating, and the first and last date of these records? Equipamento | Data | Causa | B 01/01/2017 x B 03/04/2017 Y A 05/01/2017 Y A…
-
1
votes1
answer107
viewsSimulate Database Update with Select
How I could make a select in the table below (Mysql) to solve the method (Java)? re data is_folga 10 01/01/2017 0 10 02/01/2017 0 10 03/01/2017 0 10 04/01/2017 0 10 05/01/2017 1 10 06/01/2017 1 10…
-
1
votes2
answers824
viewsReturn predefined values depending on logical condition
I got the following script mysql: SELECT con.id_crecpa, con.id_crecpa, con.descricao, con.diabase, con.dt_emissao, con.dt_quitacao FROM crecpa con INNER JOIN pessoa pes ON con.id_pessoa =…
-
1
votes2
answers63
viewsSQL query leaving a custom column data
Hello! I wonder if it is possible to mount a query that returns me a table similar to this: The appB and appC data comes from a select Count in the Calls table that returns the amount of sessoes…
-
1
votes2
answers380
viewsHow to filter records by date using SQL
I am using SQL Server and need to query in a table the most recent price record as the date. Of all the records, I need him to bring me only 1 and with the current date. How do I do this?…
-
1
votes1
answer47
viewsUPDATE update without affecting all table rows without ID
I received a table with information from some customers and I needed to give UPDATE but as the table has no ID and most of the data repeat including Cpf there is some way to give Where only on the…
-
1
votes1
answer501
viewsUse in select percentage in Firebird
I have the following instruction in Excel: (100%-2%)*2135,68 I want to make an sql: Select (100%-2%)*T.valor as TOTAL from tb_teste T In Firebird I can’t work with %. How can I get around this?…
-
1
votes1
answer56
viewsCheck whether multiple inserts have been successfully completed in Aravel
Good morning programmers, I have an application that has a report with several insertions, I need to know if all were executed successfully, I’m using the DB library: DB::insert('insert into…
-
1
votes1
answer111
viewsError using Case and Select in PL-SQL
I have this code: DECLARE BEGIN SELECT p.categoria( CASE WHEN p.categoria = 'A' THEN DBMS_OUTPUT.PUT_LINE('A') ELSE 2000 END ) FROM PRODUTO_TESTE2 p; END; Error message: Bug report - ORA-06550: line…
-
1
votes1
answer1898
viewsDifference and use between Primary Key and Foreign Key
I did a database modeling relating some tables and at the end of everything I was told that I was wrong for not having PK and FK keys. The question is, how do I differentiate a Primary Key from a…
-
1
votes2
answers953
viewsSQL - Count number of records between rows
Staff need a help in creating a query. I have a chart that ranks people per week. PessoaId | Semana | Grupo ---------------------------- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 1 | 4 | 1 2 | 1 | 1 2 | 2 | 2 2…
-
1
votes1
answer616
viewsCompare fields between two tables in PHP x Mysql
Good morning, I need some help with some php tables. I have two tables from which I need to compare data, the tables are in a database in Mysql. The scenario is as follows: I have Tabela1 with…
-
1
votes2
answers1444
viewsConvert Integer to Decimal in Oracle
how do I convert a whole number to decimal on oracle? Today, the consultation coming out this way. 75 However, I want you to go out with 2 decimal places, that way. 75.00 Below is the syntax of the…
-
1
votes1
answer35
viewsDoubt to level array after consulting SQL with Eloquent
Hey, guys, I put together the following code: $concat = array(); $products_categories = array(); $departament = $request->getParsedBodyParam('departamento'); $categories =…
-
1
votes0
answers423
viewsLoop, For, PL/SQL cursors (Doubt)
Good morning Guys, my doubt is the following, my table is so currently: Nome Idade ID João 5 Lucas 5 João 2 Lucas 1 I wish she’d stay that way: Nome Idade ID João 2 1 João 5 2 Lucas 1 1 Lucas 5 2…
-
1
votes1
answer301
viewsMysql structure in firebase/firestore
How to create a collection 1:1 and 1:n in firebase, as in the images, where I have company tables, city and categories, as would the relationship between them in the firestore, mainly the relation 1…
-
1
votes1
answer100
viewsDoubt - Case when inside a Stuff - SQL Server 2012
Guys, how do I put a case when exists within the query below. The result is currently coming out like this: Customers Drugstore, Soccer, Gelagua However, I want to put a case when exists if it is in…
-
1
votes0
answers97
viewsHow to sort values with too many characters?
good afternoon I’m doing a query that fetches values that return like this: TEST-1 TEST-2 TEST-3 TEST-4 TEST-5 TEST-10 TEST-11 but when it reaches 10 it orders by the first character for example:…
-
1
votes1
answer451
viewsSelect from two tables. How to return a single list?
I have a Processes table, with basic data and another Processes highlight, with more specific data. I need to make a select that calls some columns of the basic data and others of the specific data.…
-
1
votes1
answer73
viewsMount SQL with options
I am using Postgresql in an extension system and I have here two tables. One that stores the extensions and another that stores the permission to link these extensions. This second table is…
-
1
votes1
answer1350
viewsError "No column name was specified"
Could someone please let me know why you made that mistake? "Msg 8155, Level 16, State 2, Line 26 No column name was specified for column 1 of 'A'. Msg 8155, Level 16, State 2, Line 42 No column…
-
1
votes1
answer4525
viewsHow to handle Null fields in Postgresql
Hello, I need to know how to best use COALESCE to treat the null fields in my table. My problem is the following, I’m simulating 6 Stores and their respective cards, let’s assume that one or more…
-
1
votes1
answer512
viewsFirst() and next() methods do not work in Resultset, even when editing parameters
I need to do two iterations on the same ResultSet. For that I did the following: I set parameters in a Statement to make the cursor editable, according to my connection class constructor: public…
-
1
votes1
answer206
viewsCreating a loop with php and mysql
I need a help to create a function in PHP. I have a table in the bank at Mysql, where in a column I want to vary the numbering from 1 to 4 per record. For this I have a form where the client fills…
-
1
votes2
answers1049
viewsAdd values of different selects
Good morning To all, I have two select, I am showing next to each other, I need to add the value of one select to the other .. Is that possible? the two select are separate tables, I am displaying a…
-
1
votes1
answer426
viewsRelationship between tables in SELECT - SQL SERVER
I’m having a question on how to add a relationship between tables. Example: I am using this command to get the data. However, it returns me with the ID’s of the other tables. I would like to return…
-
1
votes1
answer562
viewsSum Count() in mysql
I have this query that returns me the amount of equal dates: SELECT `Data`, COUNT(`Data`) AS 'Quantidade' FROM sua_tabela GROUP BY `Data`; | Data | | 2016-06-09 | | 2016-06-09 | | 2016-06-09 | |…
-
1
votes1
answer78
viewsQuery Doubt in SQL Server 2012
I need that in this query come only records where the ABC CURVE column is different from the MODEL column. For example, this customer the ABC curve of it is silver and the model is diamond/gold, so…
-
1
votes1
answer250
viewsQuery to return middle text from a field
I have an appointment that returns some class names/disciplines, but I wanted you to bring me only the names of disciplines. Below follows the query result with the default…
-
1
votes1
answer312
viewsIs concatenating values directly into the query problematic?
These days a guy told me: "avoid forming Sqls by concatenating pieces of Strings. To do this is to ask to have security problems with SQL injection, and for this reason is considered a bad…
-
1
votes1
answer235
viewsC# - Subselect in Lambda and Linq
How to mount the query below in Lambda and/or Linq? select emp.cd_empresa AS ID, emp.nm_razao_social + ' (' + emp.nm_fantasia + ')' AS EMPRESA, (SELECT COUNT(con.cd_consulta) from…
-
1
votes2
answers137
viewsPrioritize line in sql queries
In a Results with 2 fields exactly equal, how to do that only show rows that the priority column is marked as 1 id | origem | destino | daia_inicio | data_fim | valor | prioridade 01 | Galeão |…
-
1
votes0
answers29
viewsHow to assign a "Code" Product to the User Request
So guys I’m modeling a database in Mysql that has 4 tables USERS REQUESTS PRODUCTS STOCKPILE A PEDIDO who owns ID_USUARIO, ID_PRODUTO and STATUS, and when the request is made he will have the ESTADO…
-
1
votes0
answers98
viewsreturn json c# . net core sql
I’m doing a test with a console application. In it I consult the database and would like to return a file json of the result. It is possible to return the query json without instantiating the…
-
1
votes1
answer203
viewsSelect all items with same Id in the same table
Very well, I will try to be as clear as possible. I have the stock table where will have there several products -> Productoid and its Quantity. In the same table the product can be repeated with…
-
1
votes1
answer94
viewsSql - Concatenate values if field is equal
I have the following select: SELECT c.codigo ,c.situacao ,c.fk_aluno FROM tb_cad AS c INNER JOIN tb_aluno AS a ON c.fk_aluno = a.id order by c.fk_aluno I need when c.fk_aluno is equal, agglutinate…
-
1
votes1
answer39
viewsHow to make this condition correctly in Mysql?
I’m wondering which affiliates have repeated enrollment within a company until the exact moment I get to make this query: SELECT DISTINCT filiados.`Filiado_Id`, filiados.`Filiado_MatriculaEmpresa`…
-
1
votes1
answer26
viewsSelecting specific SQL Server values
First thank you for your time! I don’t know much about SQL, I have a question about how to perform a select. I have some tables, follow these as an example: How do I give a select to know the people…