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
votes0
answers65
viewsMysql auto_increment of 2 in 2 (2, 4, 6...)
How do SQL auto_increment to increment the number from 2 to 2 (2, 4, 6...) in an identifier field? create table cliente ( idcliente int not null auto_increment, nome varchar(40) not null, cpf…
-
1
votes1
answer682
viewsUPDATE with several records from another table
I have a table T1 where I have the ID. I have a table T2 where you take the ID_T1(Foreign Key) of T1. I have a table T3 where you take the ID_T1(Foreign Key) of T1 and the ID_T2(Foreign Key) of T2.…
-
1
votes1
answer44
viewsThere is performance loss by using alias on oracle
In oracle there is some performance loss, even small, when using alias for tables? Examples: select user.name from user; and select u.name from user u;…
-
1
votes0
answers27
viewsPass value by URL
Hello. I’m new to PHP and I have a question. I need that when my user access the link https://meusite.com/code.php?id=**01**&key=**12345** PHP read the values 01 and 12345 and consult within my…
-
1
votes2
answers534
viewsFill List with sql return
good morning How do I fill a List with a return of an sql? What I tried to do for sure will give me an outofrange Exception List<string> list = new List<string>(); string query = "select…
-
1
votes1
answer45
viewsProblem with BD (foreign key)
My script is as follows. It is giving foreign key error and I cannot solve. CREATE DATABASE teste; USE teste; CREATE TABLE horario ( id_horario int PRIMARY KEY NOT NULL AUTO_INCREMENT, horario time…
-
1
votes1
answer75
viewsCatch the hours of the day
I have the following select to pick up the hours of the day SELECT '00:00' AS A UNION SELECT '01:00' UNION SELECT '02:00' UNION SELECT '03:00' UNION SELECT '04:00' UNION SELECT '05:00' UNION SELECT…
-
1
votes1
answer212
viewsT-SQL - Delete filter "NOT IN" does not work
I am filtering my base by store code (varchar), but the filter is not removing the store codes I want to delete from my query. This is my consultation: SELECT A.CPF , A.[Cod Loja] , B.NomeLoja ,…
-
1
votes3
answers137
viewsUsing IF and UPDATE in a PROCEDURE to update a table
I am new in SQL and PLSQL and I am having difficulty with the following situation: create or replace PROCEDURE set_value(p_variable VARCHAR2, p_value VARCHAR2) IS BEGIN INSERT INTO co_t_conf…
-
1
votes1
answer48
viewsQuery sql with ALIAS equal to column name with unexpected return
That consultation SELECT DATE_FORMAT(data,'%d/%m/%Y') AS ALIASdata FROM departamentos ORDER BY data DESC me returns the dates in the order I want 18/05/2020 17/04/2019 17/05/2018 17/03/2018…
-
1
votes1
answer79
viewsRemove numbers before the comma
I have a numeric sequence in string type '0,1;2,2;5,3;8,4;'. I need the results to come out '1,2,3,4' only the numbers after the comma. I’ve tried the following consultation: {select…
-
1
votes1
answer85
viewsValid working hours
How do I calculate the time spent on calls answered by an employee? However always within valid working hours, and knowing that the working hours of an employee is between 08hs and 18hs. For…
-
1
votes1
answer329
viewsInsert two commands (INSERT and UPDATE) into the same instruction in Sqlite, via R Language
Hello, everybody I have a problem in knowing how to insert two commands (INSERT and UPDATE) in the same instruction in Sqlite, via R Language. I don’t know if this is impossible due to Sqlite or R’s…
-
1
votes1
answer42
viewsIs there the possibility of data loss while converting text data types to nvarchar(max)?
I have a legacy database in production with data stored with the type text but there was a need to convert them to nvarchar(max) and by chance I saw that this was already a recommendation from…
-
1
votes1
answer75
viewsI need an SQL command to take all records that are equal in one field and different in another
I have a table that stores user data as email/ip/zip/city/region, records are added every time the user logs in, so if the same user logged in 2 times will be added 2 records, the idea is to check…
-
1
votes2
answers86
viewsUser with more than one profile
In the business rule of the system I am working on, a user can have more than one profile. Profiles are: administrator, evaluator and responsible. For example: So-and-so can be an administrator and…
-
1
votes1
answer499
viewsList Missing Period Days in SQL Server
How would it be possible to do with what in SQL Server when confronting a table that stores the status records of a given code with a virtual table of the period (Calendar of days) it brings me all…
-
1
votes1
answer13
viewsCase with parameter in Interbase 2017
Good evening guys, I always used Firebird, but I decided to try the 2017 Interbase for mobile apps. The following SQL works normally on Firebird and Sqlite. But I’m racking my brain trying to make…
sqlasked 6 years, 4 months ago Tallys Ferrante 13 -
1
votes1
answer102
viewsHow to create a unique index in a table so that it only has a record with a specific value in Sqlserver
Hello, I am creating a data structure in Sqlserver and I have the following situation: I have a list of contact types (person, public, commercial, etc...) This list can be changed by the user but,…
-
1
votes2
answers53
viewsSelect with LEFT JOIN and LIKE
Hello, I have created a search field, and I need to return the results of tb_orders based on the client’s name. However, only the client’s id is saved in this table, and the search is done by name.…
-
1
votes1
answer92
viewserror while trying to change a table by adding a new column of type datetime in mysql
ALTER TABLE tb_coletas ADD dia DATETIME NOT NULL generates the following error Incorrect datetime value: '0000-00-00 00:00:00' for column I didn’t understand the error, as far as I know everything…
-
1
votes1
answer96
viewsSelect where the month name appears?
At the moment I’m developing a app where I list on a table the month and the sum of consumption of each month in KW as shown in the print below: only that I n know how I would do to instead of…
-
1
votes2
answers199
viewsHow to insert grouped data from one table to another SQL
I have a 'point' table, with columns (id, Pis, date, time), which record the input and output of a product ('Pis'). I wanted to group in another table, where the data, Pis and date, are equal group…
-
1
votes2
answers267
viewsSQL helps to join 2 selects
I have 2 selects below, how can I join in only 1 select? I need to take everything that sold in a certain period (BETWEEN) by item only that at the same time I have to take what had stock of the…
-
1
votes1
answer66
viewsWhile to Analyze Select Return
good afternoon! I’m having my first contact with Mysql, before I worked with Oracle, and I came across a problem that on Oracle, I had the following structure: for a in (select id, nome, salario…
-
1
votes2
answers169
viewsHow to Make a Scan in SQL
| cliente | id | cpf | cpf_valido 2 | 1234 | 1 3 | 1234 | 1 5 | 4567 | 0 and I need to set up the table like this | de_para | id | id_para | cpf 2 | 3 |1234 3 | 3 |1234 5 | 5 |4567 To summarize,…
-
1
votes0
answers23
viewsMy SQL does not connect
I am trying to create a fingered database after installing SQLDEVELOPER on linux UBUNTU 18, however it presents the following message: The Network Adapter could not stablish conection.…
sqlasked 4 years ago Hamilton Ventura 57 -
1
votes1
answer364
viewsInner Join with like, Mysql and Datatable
Speak people, I have a problem at the time of searching a field in the datatable, i have a table of contributors, this is linked with the contributors_param, contributors_end and contributors_tel.…
-
1
votes1
answer448
viewsprime numbers from 0 to 10 in mysql
Good afternoon, I’m having trouble with this Mysql question: Show the name of the animals and the breed code. Just show the animals that contain in their respective code a prime number from 0 to 10.…
-
1
votes0
answers59
viewsModeling relationship tables
Good evening, everyone! I’d like to ask you a question. Is it possible for multiple tables to reference a single foreign key from a table? Follow the example of the modeling where the table…
-
1
votes2
answers392
viewsSQL Server - CONCAT + IF in VIEW
I have a problem and I’ll try to explain the situation. I have a client chart called ENTIDADES, there is an attribute called ID_GRUPOECONOMICO where this is a FK table GRUPOECONOMICO. I’m creating a…
-
1
votes1
answer33
viewsEfficiency in querys with different schemas [Mysql]
Is there any loss of efficiency making querys in different schemas? For example query 1 is more efficient than query 2? 1: SELECT * FROM SC1.T1 INNER JOIN SC1.T2 ON ... 2: SELECT * FROM SC1.T1 INNER…
-
1
votes0
answers17
viewsFind tables containing columns with a prefix
Hello, Is there any way to know in a mysql database which tables have columns that contain the word "commissario" ?
-
1
votes1
answer80
viewsHow to update via Linked server without using Join / relationship?
I need to use data from more than one table in the same select without having to JOIN / relationship (I want to set a value from one table to another through a Linked server). I tried the following…
-
1
votes2
answers95
viewsSubconsulta with MIN AND MAX together
How can I bring a column along with min() and max().... this is possible ? select Name, Size from Production.Product Where Size in (select MIN(Size), MAX(Size) from Production.Product)…
-
1
votes1
answer1153
viewsOracle SQL Query - Subtract Hours
Hello, I’m a beginner in SQL, and I’m in mortal doubt. This query is to analyze an execution log on a basis of my company. The problem is that the time zone of the OS is +0.00 which creates…
-
1
votes0
answers32
viewsJOIN in Bigquery
Good morning Personal. I am very beginner with SQL and need to do the following query, but Bigquery has error: Name Cnpj_radical not found Inside A at [3:6] Why can’t I call the JOIN ON alias?…
-
1
votes0
answers68
viewsColumn number of supplied values does not Mach table Definition - SQL SERVER
I have the following problem in sql server when I put the CASE clause at the end of this line of code: DECLARE @RESULTADO TABLE ( Total INT, GrupoTitulo VARCHAR(255), GrupoChave VARCHAR(255),…
-
1
votes1
answer73
viewsJoin SQL server
Good afternoon, I started working with sql to 3 mesês and I’m picking up on an application. I have 3 Tables which I have information associated with by "registration" I would like to get all the…
-
1
votes1
answer924
viewsPassword Encryption Question - SQL Server
I am developing an ASP.NET MVC system, SQL Server database, which will have logins control, and to encrypt the password, I have developed the following functions and procedures: CREATE FUNCTION…
-
1
votes1
answer202
viewsSELECT with intermediate table returning all values in the same field and separated by comma
I have the tables (and their relationships) of the diagram below: I need to do this: Bring all the fields of the TBCADCRE table and an extra column called ADQ with all the TIPADQ that the user has…
-
1
votes1
answer62
viewsPick a certain number from a string in select
I need to take a certain number that is inside a string (in case the return of a select). In the table is saved like this: CreditCash_Aderencia_AD_20180823;20180823;Arquivo convertido para CSV com…
-
1
votes1
answer35
viewsQuery to list the amount(Count) of records for a Foreign key
I’m trying to create a query that lists how many times a Foreign key has appeared from another table but I’m not getting it. I wanted to count how many times each customer appears in the order,…
-
1
votes1
answer35
viewsHow to include surplus value in the result of a LIMIT SQL query?
Hello, I have a global HDI table and would like to consult the 10 countries with the highest HDI and to include Brazil (which is not among the 10 largest ones) in this consultation. As a result,…
-
1
votes1
answer39
viewsSELECT GROUP BY SHOP
Good morning! I have 4 stores at 1,2,3,4 want to consult the last sale of a product of each store.bringing only the last 4 sales, but one of each store. someone can help me? select top 4…
-
1
votes1
answer216
viewsGrab bank ID to load into HTML select
How can I get bank ID to load into HTML select My function like this: public function ComboBox($sql, $idcampo, $selected) { $cn = conexao::getInstance()->prepare($sql); echo "<select name='" .…
-
1
votes0
answers32
viewsRun ALTER on a PROCEDURE that is referenced by another object
I’m trying to change/drop the function [xxxx] according to the code. But the following error returns to me Msg 3729, Level 16, State 3, Procedure xxxxx, Line 1 [Batch Start Line 15] Cannot ALTER…
-
1
votes1
answer430
viewsSQL Query with multiple arguments
I need to create an SQL query that may or may not have multiple arguments. Example: Pesquisa 1: "João Goiânia" Pesquisa 2: "Goiânia João" Pesquisa 3: "João Advogado Goiânia" The query must go…
-
1
votes1
answer87
viewsSQL statement in Mysql with KURDATE(), does not display API result with PHP
In this SQL what is wrong? SELECT top.id_topatletas, top.idusuarios, top.posicao, top.workout, top.data_inicio, top.data_fim, user.idusuarios, user.nome FROM top_atletas top INNER JOIN usuarios user…
-
1
votes0
answers100
viewsHow to validate a Case result
How to validate a Case result I’m taking the interval between two dates in days, I want to validate if the result and more than 120 days, has a better way than I’m doing? DECLARE @DataInicioVigencia…