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
-
4
votes1
answer71
viewsSelect brings different results
I’m having a problem at a SELECT: SELECT * FROM documento WHERE idAdministrador = '1' AND modulo = 'funcionario' OR modulo = 'atestado' I need you, if module is working or attested, to do the…
sqlasked 9 years, 2 months ago Sr. André Baill 6,946 -
4
votes2
answers1125
viewsSql - Delete Bulk Records - Delete Bulk
I have a table with about 4 million records. What is the best method to delete all of them to get the best time? Indexing helps something, since it is only a reference to find data? OBS `DELETE FROM…
-
4
votes1
answer360
viewsQuery with IN OPERATOR return only records that have all values reported
I’m having a question of how to return records from a table have all the values reported in the operator IN using JOIN in another table. I have a table of flags, colors and other making the…
sqlasked 9 years, 5 months ago Flávio Santana 105 -
4
votes1
answer4985
viewsModel Entity Relationship: Ternary vs Aggregation?
Supposing I have a ternary relationship: two entities among themselves are Nxn and the third entity is weak in relation to the relationship between these two. I would like to know the difference…
-
4
votes2
answers179
viewsDoubt about using the Inner Join
I have 4 tables in my database Tabela Cadastro - idCadastro(PK) - IP Tabela Porta - idPorta(PK) - numero porta - idSwitch(FK) Tabela Porta_has_Cadastro - idCadastro(FK) - idPorta(PK) //Observação:…
-
4
votes1
answer159
viewsWhat is the best option to escape a string before inserting it into the database. addslashes() or mysql_real_scape_string()?
I am developing a project that involves pass words among other important infomations that I need to insert into the mysql database. My question is which option should I use to escape this data…
-
4
votes2
answers861
viewsHow to generate code before entering data into the database
I need to generate a code that matches id which will be auto-incremented in the database. It will be a routine that checks the last id generated and generates a code that will be the id later before…
-
4
votes1
answer360
viewsDisplay Average in an SQL query
I want to conduct a search in a query So far I have only been able to display the total value of the records. the idea is to show the spending average. Then it would be the (total / quantity)…
-
4
votes2
answers1837
viewsGroup column sum by quarter
I would like to group the sum of one column per quarter, that is every three months. I have the following query which groups from month to month: select month(data) as mes, year(data) as ano,…
-
4
votes2
answers514
viewsC# how to do database search using parameters
I have the following code public DataTable PesquisarPorNome(string NomePesquisado) { try { DataTable tabela = new DataTable(); SqlDataAdapter adaptador = new SqlDataAdapter("SELECT * FROM…
-
4
votes1
answer404
viewsCount in Ireport
I have a report where I have the column Status, in this column I have the following status: Finalized and Pending. I created a variable and added it to the band Sumary and configured the following…
-
4
votes1
answer1222
viewsField Primary key from int to bigint
Well I need to turn my primarykay fields from int to bigint, but it is giving a problem. Follow the code below: Executing SQL script in server ERROR: Error 1025: Error on rename of…
-
4
votes2
answers1419
viewsIs there any way to know when a record was added to the bank?
I would like to know the time a record was added to the bank. I will use this information to show the time a contact was added to my schedule.
-
4
votes1
answer139
viewsfrom sql server to mysql with php
I have a bank SqlServer and I need to send data from a table to a Mysql database via php script. OPENQUERY will result within the condition I have (php script)? What’s the best way to do it? The…
-
4
votes2
answers132
viewscheck if several fields are created in the database
It was added in a table plus 7 columns, only before you need to check if this column is in the database otherwise the column creation script should not be executed. Is there a way in a single…
-
4
votes1
answer494
viewsAdd data from a column
id .. product...value...id_sale...total value 01 .. Pen.... 2,00.... 1....... 30,00 02 .. Rubber. 4,00.... 2........... 25,50 03 .. .Lapis...... 5,00.... 1........ 10,00 04 .. Pointer…
-
4
votes1
answer4693
viewsThere is a way to know the name of the Database Server
There is an sql command that can inform the server and the database in which select is running? I am available for more details
-
4
votes1
answer1886
viewsSQL: How to Count Values in Different Columns
I would like to know how to count values in different columns. Generic example: ID - COLUNA1 - COLUNA2 1 - foo - Bar 2 - - Foo 3 - Qux - Bar 4 - Bar - I hope as a result count - value 2 - Foo 3 -…
-
4
votes2
answers1405
viewsSUM in SELECT with LEFT JOIN being multiplied
I have 3 tables in MYSQL. Bill: id nome 1 caio 2 zé 3 marcelo Followers (the account id, that is, the user has 2 followers): idqual 1 1 2 2 2 3 Products (the account id, that is, the user caio has 3…
-
4
votes2
answers475
viewsInclude extremes in BETWEEN and List missing values in SQL query
Next. Imagine I have in the bank in the paid months field the following releases: 2015-03, 2015-04, 2015-7, 2015-9. If we set a period for example: from 2015-02 to today (2015-9). Which months are…
-
4
votes1
answer1161
viewsHow to set UTF8 charset?
I have a database that was created using Firebird 1.0, at this time there was no UTF8 charset available, only from version 2.0 was having this possibility, so we left the None charset. Doubts: 1°…
-
4
votes2
answers22129
viewsGet current date in mysql
Colleagues. I have a table that stores the registration dates with DATETIME(), but I need to check if the registration date is equal to the current date, so I did it as below, but it doesn’t work:…
-
4
votes1
answer1002
viewsConnect to SQL Server on remote server
I need to connect to an SQL Server service on a remote server via Sqlconnection, C#. Initially, it was not possible to find the server, but I solved this by modifying the hosts file of system32,…
-
4
votes3
answers210
viewsFunction contrary to TRIM
How to insert characters in a field varchar in Mysql? For example, in the update with Trim vc you can remove certain characters from a field varchar... but and add ? Example: update tabela set campo…
-
4
votes1
answer29006
viewsvariables in mysql: declare, set, how to pick an element from a table
Speaking of variables that can be declared within the begin, I saw that you have Declare e set only that I don’t know when to use them. I saw that you have set @x, set x, set x = x+1, set x := x+1;…
-
4
votes1
answer493
viewsHow to mount SELECT in lambda C#?
I recently asked for help to assemble a SELECT to bring the price of products How to mount SELECT They gave me this solution that worked perfectly: SELECT P.PROCODIGO, P.PRONOME, H.HISPRECO FROM…
c# sql select entity-framework-6 lambda-expressionsasked 8 years, 9 months ago André Morais Martins 367 -
4
votes2
answers16357
viewsHow to create composite primary key in SQL?
I wonder how to create a composite primary key in a weak relationship. I mean, I create the two relationship tables and I don’t know how to "pull" the primary key to the weak table. I must pull it…
-
4
votes3
answers3103
viewsHow to perform UPDATE with ORDER BY on sql server?
I would like to perform an update ordering the results of the same, for this I wanted to run an update like this: UPDATE pessoa SET nome = 'Jose' WHERE sobrenome LIKE '%Betalla%' ORDER BY nome But…
-
4
votes3
answers2362
viewsHow to Recover User Session
I just wanted to retrieve a user’s session. I have a class called User system, that identifies which user is logging in. In this class, I take the session and play for an object. @ManagedBean(name =…
-
4
votes2
answers958
viewsTake a line ID that has just been created in PHP
Hey, guys, let’s go So I’m having a problem which is this, I have a table players, a table workouts and an auxiliary table playfulness (where I’ll see if any players are training at the moment) The…
-
4
votes2
answers665
viewsSum date with int
I’m trying to make a sum of days, informed in a field int,with a field date using SQL. I tested it as follows, but it sums up the day, but ignores month and year. Is there any way to make that sum?…
-
4
votes1
answer2845
viewsRemove Duplicate Space in Middle of String
Hello, I need to remove duplicate spaces in a string and leave only 1, identico a funcao arrumar do Excel. How to do this in sql?
-
4
votes2
answers4252
viewsError: Undefined object reference for an object instance, how to resolve?
I have the method ChamadaEfetuada(MAluno) : bool checking whether the call was made to a particular student, this method is used in another method ChamadaEfetuada() : bool that instead of checking…
-
4
votes5
answers19374
viewsHow to check if a field of type text or ntext is null or empty?
How can I check whether a field of the type ntext is null or empty in where? I got the following select SELECT Subject, Notes from DocumentNotes where Notes is null or Notes = ' ' but when comparing…
-
4
votes1
answer102
viewsHow to model a set of 1 to 4 predetermined values
I am modeling a Mysql database where the main entities are documents. Among several other fields, these documents relate to one or more phases of a particular project. There are 4 basic values…
-
4
votes1
answer98
viewsHelp with SQL to find planes that have already done all routes
Assuming that there are 3 aeroplanes (A,B,C) and 5 routes and the Inserts (A-1; B-2,4,5; C-1,2,3,4,5), I intend to select only the aeroplanes that have already flown on all routes, in this case C…
-
4
votes2
answers1652
viewsSQL Server: how to create range of values based on a column with monetary values
Hello, community! I need an SQL query with the values of a SQL Server 2012 table field shown as frequency distribution. Let’s say I have, today, the field Sales (in R$), type float. The lowest sales…
-
4
votes3
answers607
viewscheck query in 2 tables at the same time with mysql
I have two tables in my BD (mysql), where: 1st Table: CADASTROS With the following fields: ID, NOME, IDADE, CIDADE 2nd Table: FUNCIONARIO With the following fields: ID, ID_CADASTRO, PROFISSAO,…
-
4
votes3
answers6231
viewsHow to compare the structure of two SQL Server databases?
I need to compare the structure DDL of two databases, where one is the production bank and the other is the approval of a system. What tools can be used to do this?
-
4
votes2
answers4608
viewsSQL - How to select or delete a column with value equal to null in a query select
I have a table in a Mysql comic that has 5 fields. This would be a model query: select * from myTable where campo1= 4 and campo2=1 and campo3 =7. However field 3 may have null value and I would need…
-
4
votes4
answers83
viewsOnly join if the above query returns records
Good staff, I would like to know what approach they would take to make a union only if the above query of the union returns values. Consider that the tables are compatible EX: SELECT * FROM Tabela1…
-
4
votes1
answer200
viewsProblem with dynamic PDO UPDATE
I’m creating a CRUD dynamic in Pdo, where I receive several parameters within an array, and within that array there may be several other arrays. The problem is appears when I am mounting SQL. I…
-
4
votes1
answer264
viewsCreate select with multiple fields
How to create a select that lists at least 03 tables and presents a field from each table at least ?
-
4
votes2
answers237
viewsError entering data into database
I’m following the lessons of php, and in the video the guy uses the command mysql, but I know he’s old and insecure and I used the mysqli, however the code does not present error, but does not save…
-
4
votes1
answer51
viewsWhat does this piece of sql statement mean?
I have this instruction in the database modeling archive and would like to know what it is. 'price_type' enum("S" "M")
-
4
votes1
answer4458
viewsHow to return day of the week and time formatted sql server 2008?
I need to make a query as follows, I have a table (script): 1 - Take the day of the week 2 - take server time in format hh:mm example: SELECT CASE DATEPART(DW, GETDATE()) WHEN 1 THEN 'DOMINGO' WHEN…
-
4
votes1
answer3721
viewsInsert X amount of characters in SQL Server field
Hello, I have two banks BDMCOM1 and BDMCOM1_V3_ALEA, both of which have a table called Saldodeproducts and the field called Codigodoproduto, in the table of the bank BDMCOM1, Codigodoproduto has 5…
-
4
votes1
answer206
viewsComparing Columns in SQL Server
Good afternoon! I wonder if you can help me. I am with the following case, we have a client who is with the version of our system VERY outdated, with this is missing several columns in the SQL…
-
4
votes1
answer500
viewsIs it OK to use SQL Server or Mysql with PHP?
I’m putting together a medium project and I’m going to model the bank, then create the tables, the views, as procedures beyond the bank itself of course. I would create everything with Mysql, but by…
-
4
votes1
answer197
viewsHow to add unpaid installments with SQL?
I have 3 tables faturas, parcelas and pagamentos. Now I need to mount an SQL to count the installments that are not paid. I have tried a SUM(CASE but it didn’t work out. Table structure faturas:…