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
-
9
votes3
answers46833
viewsHow to rename the column name SQL Table
I want to rename the column name via SQL. I am trying as follows: ALTER TABLE nomes_clientes RENAME COLUMN primeiro_nome TO nome, RENAME COLUMN segundo_nome TO sobrenome; But that way it’s not…
-
9
votes2
answers1527
viewsHow to search for saved records in the current week?
I’m doing a database query, and I plan to list the records for the current week. It would be something based on the question about retrieve data from last 7 days from current date, but instead of…
-
9
votes1
answer1020
viewsThe name of the dt_ultimo_access column was not found in this Resultset
I’m deploying a method passing an id parameter: @RequestMapping(method = RequestMethod.GET, value = "/entidadesUsuario/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public…
-
9
votes2
answers31808
viewsThe difference between COALESCE and NVL
In Oracle when we have a table that has two campuses A and B, and in selection (select) we want to show B when A is null we have two commands that present us the solution: Coalesce Select…
-
9
votes3
answers3355
viewsWhat is the difference between LOCATE and INSTR functions?
The description of the function LOCATE, in free translation, it is: Returns the position of the first occurrence of substring. The description of the function INSTR, in free translation, it is:…
-
9
votes3
answers189
viewsLEN function, know number of characters of a number
In the example below the result of the query instead of returning 7 is returned 5. DECLARE @valor money = 10.6879 SELECT LEN(@Valor) The impression I get is that when the number is the type money ,…
-
9
votes1
answer667
viewsFirebird SQL and Union ALL without duplicating items
I have an appointment SQL searching in two table one leading and one of historical only when I run the query the values come duplicated I use UNION All because if I put the UNION or DISTINCT…
-
9
votes1
answer877
views -
9
votes2
answers132
viewsHow to correctly read documentation from an SQL command?
I was studying the concept of transactions and as always the reference was the documentation of Microsoft itself (in the case for the products of the same). In the link below there is the…
-
8
votes3
answers3242
viewsHow to get the last date of a day of the week in a given month in SQL Server?
Using the T-SQL language of SQL Server, how to get, for example, the latest wednesday of the month of May of a given year?
-
8
votes1
answer50072
viewsHow to get in SQL the last record inserted according to its date
I need to get a record from a table, where this record is what in date terms was last entered. Gender: SELECT Ped.Quantidade FROM ped WHERE data <= @data But since I have several records it…
-
8
votes1
answer4798
viewsSelect fields from another table with multiple foreign keys
I have 4 tables : Lojas(nomeLoja, *IDloja*, morada, telefone, email) Bancos(nomeBanco, *IDbanco*, morada) PlanoContas(*conta*, descricao) Gestao(NIB, nConta, conta1, conta2, IDloja, IDbanco,…
-
8
votes1
answer696
viewsError trying to convert Portuguese date into datetime
I’m in trouble and I’m not finding any solution to fix it. I have a date in this format: Wednesday, 30 April, 2014 and I want to save this date in the database on type datetime. So I’m trying to…
-
8
votes2
answers6772
viewsHow to do similar word searches in SQL?
Let’s assume I have the following data in a table: John Peter Ronaldo Luiz If I use a query %like% it finds if the user type strictly. For example: if he type ron he thinks Ronaldo. But if he types…
sqlasked 10 years, 5 months ago user7261 -
8
votes2
answers39212
viewsReplace in SQL - Character to keep a piece of text
I need to modify a part in the text of a table. The records of an email are [email protected] and I need to change everyone to jf.jus.br. Only the first part of the email doesn’t change (the xxx). I can…
-
8
votes1
answer1158
viewsRecommended form for popular variables with database data
Assuming this fictitious method to obtain database data, say SQL Server: public List<DadosDTO> ObterDados() { try { comand = connectionFactory.CreateCommand(); comand.CommandText = "SELECT…
-
8
votes3
answers13600
viewsHow to get the value of a column corresponding to the maximum of another column?
I have a table with columns codigo, data and valor. I would like to get, for each code, the value corresponding to the most recent date. In what ways can this be done? And if there is more than one,…
-
8
votes5
answers42558
viewsHow to delete data from a table with dependencies in other tables
I need to delete data from a table that has dependencies on other tables. For example, so that I can delete a data from the person table first I have to delete a dependency that exists in the…
-
8
votes1
answer480
viewsIs there a way to open a direct SQL table in a data.table, without doing the SQL path > data.frame > data.table?
I want to open a direct SQL table in a date.table. When I do a query with dbGetQuery, what I get is a data.frame. I know I can then turn that data.frame into a data.table easily. But I would like to…
-
8
votes2
answers1213
viewsWhat are the advantages and disadvantages of storing session variables in the database?
From Rails 4.0, was eliminated the Activerecord Session Store, that kept session variables in the database, for "performance issues." But the functionality continues to work through a Gem. Today…
-
8
votes3
answers5509
viewsWhat’s the difference between using Inner Join or Where relationships
Good morning, I am with the following doubt, I work in a company where people bother when it comes to using inner join for the sake of efficiency and database processing, I would like to know if the…
-
8
votes2
answers362
viewsHow do I convert LINQ to SQL for Mysql?
I am trying to remove the use of SQL statements from within the system (to make it flexible as to which database will be used), use instructions Insert, Update and Delete via stored Procedure…
-
8
votes1
answer641
viewsSQL using an Array of words
Is the following I have a search field in a form where the user type for example a color or product and is returned to it a list of products with the characteristics typed in the form, the problem…
-
8
votes2
answers19790
viewsDelete all tables from a database at once
Is there a way for me to erase an entire database at once? Isn’t it drop, is to delete only the records of all tables belonging to the database.
-
8
votes1
answer6718
viewsTruncate all tables in a database in Mysql
There are ways to use the TRUNCATE to clear all bank tables? TRUNCATE tabela; This command cleans one by one.
-
8
votes3
answers17275
viewsError #1062 - Duplicate entry '1' for key 'PRIMARY'
I was trying to put one of my tables as primary key. As soon as I try to get the message: #1062 - Duplicate entry for key 'PRIMARY' The data are filled in and are more or less like this: I tried to…
-
8
votes4
answers7856
viewsCalculate Total Hours by identifying Equal Time Intervals
after a bit of a break in the head, I ask for help from you to assist in the following situation: I have a problem with SQL (Sql Server 2005) calculation of hours; Basically I have to calculate the…
-
8
votes3
answers24407
viewsWhat is the performance difference between BIGINT and INT in Mysql?
There is some negative impact on the performance of Mysql, where the Primary Key is the type BIGINT(20), instead of INT(11)?
-
8
votes1
answer14933
viewsDouble type and Decimal type, which is suitable for monetary value?
I found here in the SO a question with an answer until well accepted by the community What kind of data (double, float or decimal) should I use to represent currency in . NET with C#? I just never…
-
8
votes1
answer2706
viewsHow to count the number of tables in Mysql?
I am trying to count the number of existing tables in a Mysql database. I tried to do it the way below, but returned a syntax error: SELECT COUNT(SHOW TABLES) How can I do that?…
-
8
votes5
answers6773
viewsSeparate ddd from phone with SQL statement
I have a table with fields DDD and Phone. Some were registered correctly, others the ddd is next to the phone and need to separate. TABLE +--------------------+ | DDD | Telefone |…
-
8
votes1
answer3372
viewsSql - Select first and last record
I have the following tables: CREATE TABLE tb_lote ( id_lote integer NOT NULL DEFAULT nextval('tb_lote_seq'::regclass), ds_lote character varying(255), CONSTRAINT pktb_lote PRIMARY KEY (id_lote) );…
-
8
votes2
answers184
viewsHave images in the tables where they will be used or table with image repository?
It is good practice to create a table to record all images from a database, or I can create columns that save image information for each specific need? For example, let’s assume that I want to…
-
8
votes1
answer558
viewsIs it possible to define a connection pool for each user of an oracle database?
I searched the oracle documentation and only find ways to change this image, but nothing about creating another. Does anyone there know if it is possible what I am ordering? And how to proceed?…
-
8
votes1
answer1481
viewsWhat are "generated columns" in Mysql and what would your applications be?
I downloaded the new version of Mysql Workbench and when I was creating a table I noticed a new property of the field that is called Generated Column. On the Mysql website it says that this is a new…
-
8
votes3
answers1596
viewsHow to order records in the query according to another ordination?
I have a table with the following columns: id - id_manager - value - source - id_source When registering an "Account to Pay", insert in this table managerial breakdowns of the company. Assuming that…
-
8
votes2
answers195
viewsHow to check data range?
When requesting a vehicle reservation, the system inserts the scheduled departure and return time code (we prefer to work with fixed codes instead of schedules in order to facilitate programming).…
-
8
votes1
answer528
viewsORDER BY only day without hour
In Mysql I have a column timestamp calling for dia_cadastro (2016-06-21 11:27:32), in consultation I want to give a ORDER BY only on the day, and disregard the time. That is, if they have products…
-
8
votes3
answers1491
viewsIs it good practice to use composite keys as the primary key?
I don’t have much knowledge in database structuring. I have been trying to improve myself and I am seeking best practices on how to create and structure tables. Currently I usually create link…
-
8
votes2
answers88
viewsSql Server 2014 Null Value
I am beginner in Sql server, I am in doubt regarding the following code: declare @var nvarchar(50) = null declare @bool bit if (@var = null) set @bool = 1 else set @bool = 0 print @bool The variable…
-
8
votes3
answers10321
viewsselect from date in postgresql database
As I make a select in the postgresql database for it returns the data from a specific date, for example I have a field of type timestamp with name data_interview, I want it brings me the data…
-
8
votes4
answers835
viewsAssembling updates at runtime
When riding SELECTS at runtime we always have the problem of knowing what may or may not be coming depending on the choices made by the user. When mounting the clause WHERE we come across the…
-
8
votes3
answers15292
viewsVARCHAR2 field boundary size in Oracle
I got a column with the guy VARCHAR2 (4000 CHAR) and I’m testing the field boundary size VARCHAR2 in the Oracle. I thought there was a limit to 4000 bytes in the field, even if specifying the value…
-
8
votes3
answers182
viewsConvert date type 2016-10-04 15:51:16 to, 04-10-2016 15:51:16 to SQL or PHP how to do?
I’m doing a job to show the date and time of insertion in the script in the database, I have to show the date in the dd-mm-yyyyyy format and then the time, can I do it by the script’s SELECT or by…
-
8
votes3
answers13782
viewsChanging the data type of an sql column
Good morning. I have the spine CliTelCel char(10) on the table of Clientes, need to change char(10) for char(11). However this column already exists data, what would be the best way to proceed in…
-
8
votes1
answer1004
viewsHow to mount a SELECT to return the last status change of each id?
I have the following table: status_invoices id_fatura | status | data ---------------------------------------- XX-XX-XX | 3 | 2017-01-04 21:00:24 XX-XX-XX | 2 | 2017-01-02 11:10:20 YY-YY-YY | 4 |…
-
8
votes2
answers10963
viewsWhat is the difference between SET and ENUM in Mysql?
What are the differences between SET and ENUM in Mysql? And in what situations both are best applied?
-
8
votes2
answers21372
viewsWhat is a database database?
For some time I have been following issues involving the term procedure in database, then doubts: What is procedure? Where to use it, what’s the point? If possible examples of use clear the mind of…
-
8
votes2
answers2203
viewsIs a View faster than a regular Query?
When using a query of type SELECT * FROM myView is faster than SELECT * FROM (query para gerar a view acima) I have an appointment and would like to curl or make it faster, but I am in doubt if I…
-
8
votes0
answers72
viewsSELECT to get many lines in PHP
I’m a beginner in PHP and Mysql and need to know what I do to get all users registered in a database when the number of users reaches thousands? I registered 300,000 users in my database and would…