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
-
3
votes1
answer89
viewsHelp with MYSQL TRIGGER
I need to assemble a Trigger that before deleting a user it checks if there are occurrences linked to the user in question, and if there is, not allow delete, but never worked with Triggers. Someone…
-
3
votes1
answer261
viewsC#,SQL,SQLITE How to return SQL command from an action
I have a question in C# and SQL commands, I am currently using Sqlite as a local database. In my application I enter entries in the database, so far so good, but I wanted to know if there is any way…
-
3
votes2
answers1032
viewsBring all records if parameter is different
I have a table contrato with the countryside concluido of the kind tinyint(1), if it is 0 it is not completed and if it is 1 it is completed. I will pass this value per parameter to the query, as I…
-
3
votes0
answers161
viewsSearch in sql server 2014 with php
I am using Sql Server Express, I have an instance installed individually on two virtual machines on the server, one of the instances installed is the Sql Server 2008, and the other is Sql Server…
-
3
votes2
answers407
viewsSaving file path in Mysql
I’m having trouble saving file address in the database. When saving the address in the bank it is adding the amount of times I used the OpenFileDialog to save a file. Always save the address like…
-
3
votes2
answers2280
viewsChange Varchar field to Date Mysql
I need to fix a table that was built wrong, the field that would store the date was created as varchar. With this structure I can not select a certain period, because varchar are ordered from left…
-
3
votes1
answer189
viewsODBC PHP / Oracle - UPDATE, INSERT, DELETE
I’m in a project using PHP and Oracle. the connection is OK, with this code I can run all the selects I need normally, what I can’t run are INSERTS, UPDATES and DELETE. Would anyone know why?…
-
3
votes1
answer674
viewsSP2-0552: Unstated Bind variable "19"
I am using Oracle SQL Developer to finish a project, when I was popular the database, the software accused an error in the following line: INSERT INTO musica (cod_musica, data_composicao, titulo,…
-
3
votes1
answer2399
viewsDynamic Sql Server Query
Gentlemen, I have the following problem: I have to set up a consultation that works with various views, for example, one of products or one of people. I’m doing some tests with this code: declare…
-
3
votes1
answer2756
viewsWhat is an Associative Table?
Well, I see some examples of code using associative tables. But I’m not sure what this term means, its applicability, the concept etc... What is an associative table?
-
3
votes1
answer350
viewsChange Sequence value with subselect
I have the following case: I need to change the value of some sequences according to the max(id) of the table, I am trying to do something like: ALTER SEQUENCE CFOP_SEQ INCREMENT BY (SELECT…
-
3
votes3
answers717
viewsSQL - Return zeroed records
Good morning, I have a query that is only returning the months with sales consumption, which should be correct. Only now a blessed user wants me to return every month, including those who have no…
-
3
votes2
answers2419
viewsPrimary key in associative table(Many for many)
Good night. I have the following question in relation N to N. Foreign keys become a primary key composed of the associative table. Correct? Does this guarantee that there is no repetition between…
-
3
votes2
answers246
viewsDATES applied SQL Decode function
I have a question I need to make a select where I need to show if a client’s registration is active or not, in the database is treated as follows, has a field date of exit if the field is empty the…
-
3
votes2
answers10959
viewsHow to select between dates
My question is quite simple, I intend to ask a SELECT between dates, from a given table, where the status='1'. I mean, I have for example: $data1 = 13/01/2017 $data2 = 20/01/2017 I want to select…
-
3
votes2
answers1567
viewsHow to handle string to avoid SQL Injection?
I have the following code: $nome = $_POST['nome']; $ip = preg_replace("/[^a-zA-Z0-9\.]/", "", $_POST['ip']); $porta = preg_replace("/[^0-9\s]/", "", $_POST['porta']); $site =…
-
3
votes2
answers328
viewsWhat would the query look like to return values in a given range?
I have a table with the following Rows: code (int) vaccine (varnish) dt_maturity (datetime) I need a query to return all vaccines that will win in the interval of 10 days, counting today’s date. I…
-
3
votes3
answers149
viewsHow to generate new code from DBO
I have a table with the name Produtos in which I inserted 3 products for testing. Now I’m assembling the product registration form and I need to always generate a sequential product code from the…
-
3
votes1
answer967
viewsSql server turn a column into multiple rows
Good morning I have a table called books that has 3 fields, Code, Name and Chapters Example of content: 32 - Jonas - 4 i need after select me return the following result Codigo e Capitulo 32 1 32 2…
-
3
votes1
answer59
viewsHow to select double contacts from a table
I have 2 tables : Users [id, name, etc ...] Friends [id, idUsuario, idAmigoI] In the Friends table, idUsuario corresponds to the id of the user who has the contact and idAmigo the id of the user who…
-
3
votes1
answer278
viewsHow to calculate cumulative total of 365 days joining two different years?
I’m trying to verify the accumulated total of a certain amount, which starts in September of a year and goes through August of the following year, and then starts again. I’m doing this with a long…
-
3
votes2
answers473
viewsInsert 1000 records into table with uniqueidentifier as primary key
I have to add, 1000 records in a given table. It contains the Field Name. I have the Script, which does the mass insertion. However, the primary key of this table is a uniqueidentifier(Guid()) how…
-
3
votes5
answers1923
viewsIs it possible to update the first 100 lines in sql(server)?
UPDATE tbl_venda SET produto=1 WHERE produto=3 The problem is that there are more than 10,000 sales lines and the pc hangs. I wish it was possible to do 100 to 100, 500 to 500, so it doesn’t get…
-
3
votes2
answers83
viewsResult SQL has field and index
I have a PHP function to automate the queries I do: //arquivo funcao.php function executaSql($sql, $param=array()){ try { include "config.php"; $q = $conn->prepare($sql); $q->execute($param);…
-
3
votes1
answer103
viewsDoubt in SQL ORACLE query
I am thinking of making a View for the development of reports, and I bumped into the following problem. I would like to join columns PUBLICO1, PUBLICO2, PUBLICO3, PUBLICO4 in a single column. Ex.:…
-
3
votes1
answer6005
viewsUsing Case When with Leftjoin
I am mounting a proc, but depending on the value of a parameter, I would like left Join to be different. I tried the kerys below: That works, but the else as null or even without the else, if the…
-
3
votes2
answers100
viewsDelete sectors and their descendants - PHP
I have the following structure table: CREATE TABLE IF NOT EXISTS `setores` ( `set_cod` int(10) NOT NULL AUTO_INCREMENT, `set_base` int(10) NOT NULL, `set_setor` varchar(50) NOT NULL, `set_data`…
-
3
votes1
answer283
viewsTuples separated by commas
I’m making a query in the database (mysql) where I have a code and by this code there are several types of people. I need when you do the query come like this ID | NOMES 1 | Fulano 1, Fulano 2,…
sqlasked 8 years, 3 months ago Renan Rodrigues 3,709 -
3
votes2
answers87
viewsSQL Query Simple
I’m starting with Database, and I came across a situation that I just don’t understand. I wanted to get the name of the student and the name of the subject that are in table 3 in the case…
-
3
votes3
answers367
viewsRun a SELECT JOIN with conditions for different tables
I’m making a system of ticket where I have the message table of each ticket. This message can be sent by both an administrator and the user who opened the ticket. With this, I have the problem when…
-
3
votes2
answers458
viewsSearch for next 7 days records in SQL
I have the following SQL SELECT `age`.*, `inte`.`int_nome`, `inte`.`int_cod_unidade`, `set_uni`.`uni_titulo` as set_unidade, `set_cur`.`cur_titulo` as set_curso, `set_sta`.`set_setor` as set_status,…
sqlasked 8 years, 3 months ago Sr. André Baill 6,946 -
3
votes3
answers756
viewsHow to remove duplicate data in this query?
Eai personal blz? Next I’m using this query: select products.id as product_id, offers.id as offer_id, companies.id as company_id, products.title, (ST_Distance(companies.location, 'POINT(-48.030322…
-
3
votes1
answer539
viewsmysql error with foreign key
I am creating a template but I am running into an error when I am going to create foreign MYSQL keys from a "Cannot add Foreign key Constraint" error. follows my sql. use fatec; create table aluno(…
-
3
votes1
answer467
viewsSQL/ORACLE Filter active records in the month
I have a table that records my records where a column records the data_inicial and another column to data_final. I need to generate a report where the user searches all records that were between the…
-
3
votes1
answer1199
viewsSelect and do not return values containing xxx
I’m making the following select: SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME; In this I have the name of the tables, the problem is that for each table I have a table_AUD, ex: PESSOA…
-
3
votes1
answer458
viewsorg.hibernate.Propertynotfoundexception: Could not find Setter for sum on class Class
People I’m trying to list the best selling products using Sqlquery (if anyone knows of other ways to perform as eg using Criteria, Projections also accepted) with Hibernate, but this error is…
-
3
votes2
answers37
viewsWhy does To_char(3E4) not result in '3E4'?
Guys like me convert an exponential number (NUMBER) to string (VARCHAR) but it is expressed equal?? Example: SQL> SELECT TO_CHAR (NUMERO) NUMCONVERT 2 FROM (SELECT 3E4 NUMERO FROM DUAL);…
-
3
votes1
answer6191
viewsSum of hour+minute oracle/sql
Good afternoon, I have a table that stores times (hour:minute), I would need to group by date and add these intervals, for example day 01/03/2017 I have 04:35 of duration time. I tried a lot of…
-
3
votes2
answers65
viewsHow to mount this SQL
I have these tables: Client: cliente ------- id nome id_municipio Municipality: municipio ------- id nome Regional: regional ------- id nome Regional_municipio: regional_municipio -------…
-
3
votes1
answer1315
viewsSQL - scope_identity() for INSERT SELECT
There is something similar to scope_identity() to return the ids created by giving a insert on the basis of a select? (insert of more than one line simultaneously). OBS: scope_identity() only one of…
-
3
votes3
answers8033
viewsDo not repeat records in a Join
I have two tables: one with 1009 records and another 11949. When I do a Join, I have 11949 records, of which 1009 table records are repeated several times. I need to select with Join, but bring only…
-
3
votes1
answer115
viewsProblems with select in multiple tables
I’m trying to make the conversion of a select from sql server to Dapper, as it was very big, I’m wanting to leave more lean and readable... However this appearing error in some passages SELECT…
-
3
votes1
answer1111
viewsModeling database table
I am creating a database that stores an electronic invoice - "Nfe" received. Within the items of a tax note are always linked taxes. Table example tblProdNFe_Entrada with the table…
-
3
votes1
answer683
viewsSelect fields to return in an SQL INNER JOIN
As I can in a single SQL statement line, like SELECT * FROM table1 INNER JOIN table2 ON xxxxx, and the desired return would be formed by all fields(columns) of table1 and only one field(column) of…
-
3
votes1
answer653
viewsSelect with two tables and one condition in each with MYSQL
I have two unrelated tables. One is of reports, where it contains names of teachers and their respective subject, the other table is called login, where it contains credentials of each teacher,…
-
3
votes1
answer301
viewsError when connecting PHP to SQL Server via ODBC Linux
I am making a connection in no windowns via php to SQL SERVER and it is going normal, in a machine where the php server is linux this giving the following error: Fatal error: Uncaught exception…
-
3
votes1
answer42
viewsFind SQL values
I need help, I have an e-commerce table called product table, I need to list the product name, sales value, products with stock between 20 and 30 and any part of the product name has the letter "A",…
-
3
votes2
answers725
viewsSelect Aninhado
I need to develop a screen that shows the TOP 50 most accessed menus. Tell the number of accesses and which city it belongs to. Sort by number of accesses and select values for the last 30 days. To…
sqlasked 8 years, 1 month ago Carla Vieira 31 -
3
votes1
answer174
viewsSql Server Stored Procedures
I am starting the development of an application, basically it is a managerial control of companies. The application will issue NFC-e, Nfe, control stock, finance and etc, the database will be hosted…
-
3
votes1
answer689
viewsAcademic ER "system" modeling
Guys, can someone help me? I’m doing a database job where I have to do an academic "system", I developed this photo ER, I have doubts of type: How do I make the teacher store the notes and…