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
-
0
votes4
answers534
viewsHelp with distinct
I have the following sql query: select nome, data, situacao from cadastro The result is like this: MARIA 01/01/2018 0 MARIA 15/01/2018 1 GISELE 15/01/2018 0 CICERA 08/01/2018 1 ANTONIA 20/01/2018 0…
-
0
votes2
answers6656
viewsHelp with SQL error 1064
Could you help me solve this problem here? use bancoteste: create TABLE login{nome varchar(10),senha varchar(10)); INSERT into login VALUES (`root´,`root´); SELECT * from login Error: SQL Error…
-
0
votes1
answer116
viewsSQL/PHP query
I am trying to make a query in the database in 2 tables and pull the data to page with a condition would be this if the id_noticia of one table equals the id of the other when clicking on the image…
-
0
votes1
answer2207
viewsError convert Query SQL Server date and time
Guys, I’m trying to run the query below, however, the following error is occurring. " Failed to convert string date and/or time.". I have done some other conversions, but without success. select…
-
0
votes1
answer940
viewsUse a java Resultset to print an entire table on the screen
I know that with the resultset we can do several things with a SELECT done in some table. For example: I know that we can take a table and print its contents, listing which columns we want with…
-
0
votes1
answer1231
viewsHow to increase the Grid View Result font in SQL Server Management Studio 17.9.1?
I want to increase the source of Grid View Result because it gets too small in a full hd notebook of 15.6. I’ve been to the Fonts and Colors options but I can’t find the option:…
-
0
votes1
answer407
viewsSet a condition in order by mysql
I am having doubts about a subject related to order by. In my table you have the following information: ID | ORDEM | NOME 1 | 0 | NOME01 2 | 2 | NOME02 3 | 1 | NOME03 I want to give a select where…
-
0
votes1
answer68
viewsError while running script
Guys, I’m trying to run the query below, however, the following error occurs. "Conversion of a data type varchar into a data type datetime resulted in a value outside the range.". select…
-
0
votes1
answer79
viewsExchange WHILE for GROUP in SQL
I need an SQL function to get data grouped by month. I have in the column CPCCodeID codes (ex: 512456). I need to count and group by the first two digits. I need it separated for months (!!!) and to…
-
0
votes1
answer264
viewsConstraint in a key Primary - SQL
I’m having a problem intender what the intention of this code below when putting a Constraint to create a primary key for a foreign key. CREATE TABLE Customer( IdCustomer integer PRIMARY KEY NOT…
-
0
votes1
answer114
viewsSelect result, and show only if all are equivalent
I’m maintaining a database, and I’m in the next situation; in the bank I have 5 columns in a table, are: ID(PK)|Idticket|Result|Prestadoconta|Date I have to filter for the user to see, only the…
-
0
votes1
answer62
viewsStored Procedures parameters
I have a question and I wanted to ask for your help. Next: I have a proc and I want when I don’t pass a parameter it returns to me null and when this happens bring the date of the day -1 and time…
-
0
votes1
answer278
viewsError adding ON DELETE CASCADE two Foreign Keys from the same table
I am deploying a table to save the messages, in this table I have source users (sender) and destination user(recipient) from the same table: user. When trying to add the constraints to the message…
-
0
votes1
answer254
viewsInsert using parameters in the C# application for the Oracle database error: ORA-01036: invalid variable name/number
I noticed that there are many questions about this error but none solved my case the connection works normally, there is the Insert method(): public bool Insert(ArrayList arrAlunos) { vsql = "insert…
-
0
votes2
answers75
viewsAdd SUM() to querry results
I have this querry that gives me the total number of lines that start with the same code USE CCILCDatabase; GO DECLARE @mes int; SET @mes = 1; WHILE (select @mes) <= 12 BEGIN SELECT…
-
0
votes1
answer236
viewsConvert String to INT
How to convert variable string fg in one whole? if (connectionIsOpened) { String s = "INSERT INTO jogador(nome) VALUES " + "('" + this.playerName + "'" + ")"; connection.executeUpdate(s); String fg…
-
0
votes1
answer346
viewsRelationship between 4 tables
I have the tables: -- NORTE -- create table tb_indices_norte( id_norte int not null auto_increment, localidade varchar(30), sem_epi int not null, totOvos smallint, num_pos smallint, num_inst…
-
0
votes0
answers34
viewsTake the contents of the columns that are inside a while
Good night! I’m trying to use the speakers of the second while to insert into a table, but I can’t get the value of the columns. I’ve used several combinations of quotation marks and nothing. This…
sqlasked 6 years, 9 months ago Sergio Paiva 15 -
0
votes3
answers2912
viewsCreate Trigger with update setando field through a function
I’m looking to use a trigger to update the field of a table whenever there is an Insert in this same table. The problem I’m having at Trigger is that the update doesn’t work, it follows Trigger:…
-
0
votes1
answer71
viewsCounting the quantity of products
Is there any query that returns the quantity of products example I have 10 cell phones, 5 brand a and 5 brand b. This way and not the total count, if yes how to do? Counting them by id.
sqlasked 5 years, 9 months ago Rafael Dias Zendron 67 -
0
votes1
answer89
viewsHow to remove the special character that forms inside a String in SQL?
I am using the excerpt below in my code, but when inserting > inside a String, it returns the result as > ;, the same is converting to HTML entity, as I can use '>', without problems?…
-
0
votes2
answers6651
viewsSelect higher value from the latest date
I have a table estoque where records of all supplies are stored, with the date of entry into stock, the supply code and the unit value of the piece, my need would be to take the highest unit value…
-
0
votes1
answer48
viewsProblems with JOIN and CONDITIONS - sql
I’m having to fetch in 2 table some data with certain conditions, follows the situation: table: tbTransmitted => Colunas: Code - Qty - On request table: tbEstoque => Colunas: Code - Qty -…
-
0
votes2
answers358
viewsTrigger to Retrieve Last Record Inserted in PL-SQL Table
I have a Rigger that after being inserted a new user in the table tFunctioning I must fill another table tPlanoSaude with the data of the employee. employee table table Health Plan Code of the…
-
0
votes1
answer407
viewsError generating PLSQL file on oracle!
Code CREATE OR REPLACE PROCEDURE CRIARARQUIVOTXT AS Arquivo_saida UTL_File.File_Type; Dir_Arq VARCHAR2(60); Cursor cur_arq is Select f.NOME from tfuncionario f; BEGIN -- Diretorio do Arquivo Dir_Arq…
-
0
votes3
answers98
viewsHow to check if the record exists in the database and update if it exists
How to check if the record exists in the database and update if it exists I tried this way Select if((SELECT COUNT(*) FROM Pessoas WHERE id = 0) > 0, ( UPDATE Pessoas SET Name ="João" where id =…
-
0
votes1
answer30
viewsHow to Properly Organize Tables in a System
I am developing a system for a school where the teacher will create the proof by the system, I have 3 entities: Proof, Question, Alternative, I would like to know the best way (in the database) to…
-
0
votes2
answers1609
viewsPython Mysql database connection
Trying to make the connection to my database, but is returning me the following error! Exception has occurred: Attributeerror 'Connection' Object has no attribute 'execute' Exception has occurred:…
-
0
votes2
answers799
viewsDelphi - Grid does not display all fields of the SQL statement
I’ve been racking my brain for two days and I can’t figure out the problem. I have an SQL (Tfdquery) statement written in the code that selects three fields from a table to display them in a Dbgrid.…
-
0
votes0
answers46
viewsHow can I count Ikes from the relationship table
Need Select the posts along with the corresponding Ikes for each post. Cosegui select what I want, but when I use the error COUNT see in the first img. Dice The two tables also the post and the…
-
0
votes1
answer126
viewsdatabase backup
I looked in some tutorials here on the site, but I did not find one that fits what I’m looking for, so I followed this tutorial Backup & Restore Sql Server database in C# it even has a link in…
-
0
votes2
answers157
viewsCreate a Join between two classes in my repository
I have a repository for my class PessoaCadastro that relates to the class Pessoa. I need to create a method GetJoinAll(...) show me all the table records PessoaCadastro that are related to Pessoa…
-
0
votes0
answers36
viewsData Issues Node.js (SQL Data)
I have a question regarding receiving SQL data in a Javascript array. I have the login information and everything, related to the server, but the issue is not the connection, is to save the data in…
-
0
votes0
answers25
viewsStrange behavior with group concealment
I have a strange situation in my report. It has two groups of lines where the first level is hidden and expands when selected in the second, but in the report view it is not reduced. He’s showing…
-
0
votes2
answers31
viewsCompare shorter term between Asp.net columns
Making order system, I have several warehouses, let’s assume I have to compare 2 warehouses that have shorter delivery time using entityframework,how would I do that? I’m trying to do more it just…
-
0
votes0
answers86
views -
0
votes0
answers29
viewsWhat is metadata and how do they work in databases?
I’ve been researching metadata, and they said it’s faster to bring information when it comes to thousands of data lines. I have a huge database and I wanted more security and more fluidity when it…
sqlasked 5 years, 8 months ago Andressa Santos 15 -
0
votes3
answers1324
viewsSelect records from one record to another in sql server
I want to select from record 20 to 50 in SQL SERVER, but I’m not getting it! I’m wearing it like this: SELECT * FROM table OFFSET 20 ROWS FETCH NEXT 50 ROWS ONLY But it doesn’t work! I know you have…
-
0
votes0
answers232
viewsERROR 1442 - Trigger AFTER INSERT - Mysql
My database has the following structure: CREATE TABLE BAIRRO ( BAI_COD INT(4) AUTO_INCREMENT NOT NULL, BAI_NOME VARCHAR(200)NOT NULL, CONSTRAINT PK_BAIRRO PRIMARY KEY(BAI_COD) ); CREATE TABLE…
-
0
votes1
answer27
viewsInserting Data Conditionally in MYSQL
I have a table: conluna1, column2, column3.. The first two columns have integer data, 0 and 1, while the third column is without even a record. I would like to fill this column according to one…
-
0
votes1
answer84
viewsHow to bring all items that have no reference with a given table [SQL]
I am using Nhibernate to make a query in sql in C#, but I have a doubt. I have the following structure: public class Pessoa { public long Id {get; set;} public string Nome {get; set;} } public class…
-
0
votes2
answers264
viewsMigrate EXTRACT(YEAR_MONTH,data) from Mysql to SQL Server
I have a Mysql query that would need to convert to SQL Server. I tried with datepart SQL Server but it does not maintain the main feature of the Mysql query, which is to maintain the range month by…
-
0
votes1
answer50
viewsList zeroed results in query
Good morning, you guys, I need your help in a select, I’m doing a search, I have a 4 tables: user, question, alternatives and answer. In the answer table I save the user’s Cpf, the question id and…
-
0
votes1
answer2576
viewsHow to subtract hours from a date sequentially in SQL?
I have several fields with data, hora and sector: Sector|Horas|Data ------|------|----- Corte |01:00 |12/03/2019 17:00 EXP |00:30 |12/03/2019 17:00 Etc I want to subtract the time of the date, but…
sqlasked 5 years, 8 months ago user141887 1 -
0
votes1
answer55
viewsSearch table field with query result from a different table?
I asked a question recently: Find lines of the last 24 hours that repeat the most (Mysql) And it was answered, now I have another question. I do the following to seek from and to of the most…
-
0
votes2
answers5935
viewsIs there any clause similar to LIMIT in PL/SQL
I am using PL/SQL and would like to know if you have any clause or sql script that is similar to sql LIMIT clause, I’ve been searching here and found rownum < = X , but does not meet what I want…
-
0
votes0
answers42
viewsInsert primary and foreign key at "same time" SQL
Suppose two tables "company" and "employee" within employee has a key Foreign for the company When the user goes to create a new company he answers a form that in this form he adds the name of the…
-
0
votes1
answer187
viewsSearching character in Specific Position - SQL Server
Hello, can anyone help me? I am building a query and I came across some problems in the way the bank was structured. I have a base with several phone numbers, and I need the 5°digito to be = 9. I…
-
0
votes2
answers74
viewsVIEW and JOIN, return the product, and the value with the latest date!
I have the following tables I created. CREATE TABLE produto ( codigo INT UNSIGNED NOT NULL AUTO_INCREMENT, nome VARCHAR(128) NOT NULL, url VARCHAR(255) NOT NULL, qde_min SMALLINT UNSIGNED NOT NULL,…
-
0
votes1
answer141
viewsSave time of registration in the database
I have a form and whenever someone register, I need to save the time of registration in my table Historico2 inside the property DateTime? Quando. public partial class Historico2 { public int ID {…