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
answer18490
viewsAdd Column in SQL server
I’m working on a system that I need to realize a sum that will be made into a view SQL Server. In C# I know how to resolve this. I would like to resolve using SQL. ColA ColB 200911 1634,50 200911…
-
3
votes3
answers563
viewsProblems with LEFT JOIN
I’ve been racking my brain for a few days with SQL on something that should be very simple, but I can’t fix it. I want to get all data from the table [Numorder] including those not in the table…
-
3
votes1
answer1106
viewsChange "Character" and "collation" settings
I have a configuration in a database as follows: SERVIDOR 1 show variables like '%version%'; innodb_version 1.1.8 protocol_version 10 slave_type_conversions version 5.5.19-log version_comment MySQL…
-
3
votes2
answers1627
viewsFetch data from last 7 days from current date (2014-12-11 11:06:09)
After viewing the that question, the following doubt arose that is, in the case that the date field is in the following format 2014-12-11 11:06:09, how to return only the last 7 days?…
-
3
votes1
answer2044
viewsquery by day number of Mysql week
The week has 7 days, so I want to be able to make a query that the user according to the day of the week you choose presents the result: mysql_query("SELECT * FROM tbl_eventos WHERE WEEK(data) =…
-
3
votes1
answer872
viewsChange Mysql column information with UPDATE
In summary through PHP below I can send the specific information already recorded in the column in the BD, only that, in addition to just "sending" the data there, I would like a function that…
-
3
votes0
answers1429
viewsArtificial Intelligence using PHP and Mysql
I am looking for information on artificial intelligence using Mysql and PHP only, I did not find much information that would guide me correctly, I want to develop a small chat with virtual…
-
3
votes1
answer83
viewsI can’t perform a Select
I’m having a question about how I should ride the SELECT for a particular function. The scenario is as follows: I have 4 tables: Tab_Pessoa - Tab_Cliente - Tab_Autorizado - Tab_Cliente_Autorizado.…
-
3
votes1
answer891
viewsTrigger that calculates and updates age
I want to create a Rigger that when firing calculates the customer’s age on each table row and updates itself. I tried it this way: create trigger Atualiza_Idade on cliente for insert,update,delete…
-
3
votes1
answer169
viewsAdd value to SQL table instead of replacing
Using the following code: UPDATE `login` SET diasvip = '".+$_POST["qntvip"]."' WHERE userid = '".$_POST["userid"]."' When I execute, it replaces the diasvip by the value posted instead of adding the…
-
3
votes2
answers1023
viewsDatabase modeling problem
I created a system that has control of sales (id, id_vendedor, produto), salesman (id, nome, id_equipe) and team (id, nome) in a company. Example: "John has id: 1 and belongs to the team: Blue; in…
-
3
votes1
answer147
viewsWhy does the binary conversion of SQL Server not return a binary value?
Why when I use the following command in SQL Server 2005 select convert(varbinary(16),N'123') returns 0x310032003300 and not 1111011 that would be the binary value?…
-
3
votes1
answer1552
viewsHow to connect to an existing Sqlite database using PDO?
I want to connect to a database that already exists using PDO and sqlite in PHP, and here is the code I have: class Database extends PDO{ public function __construct(){ parent::__construct("sqlite:…
-
3
votes3
answers271
viewsHow to optimize SQL queries containing SELECT-related DELETE?
$a = mysql_query("SELECT * FROM catalog_items where page_id='84'") or die(mysql_error()); while ($row = mysql_fetch_array($a)){ $base_item = $row['item_ids']; mysql_query("DELETE FROM items_rooms…
-
3
votes0
answers378
viewsHow to see the final query that was executed? PHP PDO
I make my appointments as follows: $sql = "Select * From minha_tabela Where meu_campo = :parametro"; $sql = $db->prepare($sql); $sql->bindParam(":parametro", $parametro, PDO::PARAM_STR);…
-
3
votes2
answers2291
viewsStoring measure drive in Mysql table
In one of my forms it will be necessary to collect the height of the user in meters. However, this form can be in English or in Portuguese. If you are in English this height will be in feet (Feet).…
-
3
votes1
answer923
viewsHow to sort and filter queries between two tables?
I have two tables, one of posts (posts) and another of friends(Friends). In my script there is an area of feed where I would like to present the latest posts from the logged user’s friends. But…
-
3
votes1
answer2019
viewsCould you add a UNIQUE field that accepts nulls?
I can create a field that accepts nulls and say it is unique? This table of mine, the CRM indicates that he is a doctor and not a normal person, he has to be unique, but has to allow nulls. This…
-
3
votes1
answer920
viewsHow to improve the performance of this SQL query?
Hello, first I will pass some pertinent data to the query. Tabela Contrato (id, id_cliente, status [ativo/inativo]) Tabela Cliente (id, nome) Tabela Dependente (id, id_cliente, nome, status…
-
3
votes1
answer968
viewsHow to verify the occurrence of a string in a row and pick up x characters on the left and y on the right?
I’m having a problem with a Mysql query and I’m looking for help. Suppose I have many lines in the PROCESSES column and one of them is like this: IBAMAPROCUR: DF00025372 ADRIANA MAIA VENTURINIAPDO:…
-
3
votes1
answer145
viewsInsert into database recording in half
I take the name of the news and insert in another table, but one of the fields is going by half, follows image of print: Database Source code of where send: <input name="nomenoticia"…
-
3
votes1
answer86
viewsORACLE EXPLAIN PLAN, wrong values?
I’m using the explain plan of Oracle to raise some statistics and the following problem is happening: When I created the database, I created an X table with 50 Inserts. Soon after, I inserted about…
-
3
votes2
answers66
viewsProblem to mount query
I cannot mount a query, the logic is: Select produtos with categorias different products, being the products with more points, so I will have a product of more points of the category X, another of…
-
3
votes3
answers5605
viewsColumn 'column name' in Where clause is ambiguous
I’m trying to ride a left join where I want the results of a particular code. My SQL is: $resultado = mysql_query("SELECT CA.DAT_EHORA_EVENT, CA.TXT_NOMEX_EVENT, CA.MEM_DESCR_EVENT FROM tbl_CLIENTES…
-
3
votes1
answer167
views -
3
votes3
answers2456
viewsPhone and CPF fields in SQL?
I’m wondering what type of variable to create for the CPF and Phone fields in the database, they should be saved like this: (34) 9652-5214 134.124.214-47 With nchar wouldn’t complicate the search?…
-
3
votes1
answer187
viewsLinq query with Count
I’m doing a query that has some joins and a Count, but I want to do it with Linq. This is my Query. sbSQL.Append("SELECT grproj.cdgruproj as Id, grproj.dsgruproj as DescricaoGrupoProjeto, ");…
-
3
votes2
answers99
viewsSet roles for users stored in Database
How to structure in the database a structure of user roles (ordinary users, entrepreneur, site_amdin), each user will have different functionalities, different powers in the application that will…
-
3
votes1
answer2293
viewsHow do I add a new column between 2 columns in Postgresql?
How do I add a new column between two existing columns in my Postgresql database? In Mysql I use the function AFTER to add one column after another, and in Postgresql? How do I do this? SQL ALTER…
-
3
votes1
answer92
viewsPostgressql - Stored Procedure
What’s wrong with this stored procedure? CREATE OR REPLACE FUNCTION public.sp_teste ( IN varchar, OUT codigo integer, OUT setor varchar, OUT grupo integer ) RETURNS SETOF record AS $$ begin return…
-
3
votes1
answer492
viewsSelect com Update
Would anyone know if there is an SQL calling to run a SELECT using LOCK IN SHARE MODE registry and running an UPDATE at the same time? example: SELECT * FROM Nome_Tabela WHERE id = 5 LOCK IN SHARE…
-
3
votes3
answers644
viewsDiscovering the SQL of a Resultset
I have a Resultset java object that I don’t know the SQL/parameters that generated it. Would you like to know how to get the SQL used to create it? would have something like : rs.getStm.getSql ?…
-
3
votes1
answer77
viewsCount Values with PHP and SQL
Everybody, Good afternoon. I have the following question. I have a questionnaire with 10 questions, the answers to these questions can be 0 to 5, I would like to make a while out counting the…
-
3
votes2
answers3054
viewsFormat CPF column with regular expression
In a table containing the column CPF I would like to format it in order to present the content properly. By appropriate way I refer to the format 999.999.999-99. It is possible to format this…
-
3
votes1
answer4634
viewsHow to change an SQL Server View
I have some Views on Sql Server that were implemented by other people ,but they didn’t leave any documentation or scripts, I believe it is possible to access to change and maintain them? But I don’t…
-
3
votes2
answers452
viewsHow to get the sum of three tables in sql
I have 3 tables, being them: Schoolhouse: id, id_escola and nome_escola; Professor: id, id_escola and nome_professor; Students: id, id_escola, sala_aula and numero_alunos; I am aware of the joins,…
-
3
votes1
answer1892
viewswrite json file to database
it’s a good idea? was thinking of doing a project where the user will create several elements dynamically (tables, choose a certain option, fill in etc), these elements generated dynamically should…
-
3
votes2
answers2034
viewsPassing values from a select to subselect
I have the following query: SELECT rp.colaborador as codigo_, t.nome, count(rp.*) as presencas, ((100 * (select count(rp.*) from empresa.cad_reuniao_presencas rp join empresa.cad_terceiros t on…
-
3
votes2
answers608
viewsShow zero in group by SQL Server
I have a table that calls Ordem, on it has a field that represents the status of the service order (0 to 7), I need to plot a graph in Ireport, only I wanted to display in the legend the status name…
-
3
votes2
answers792
viewsLimit number of Group By occurrences
I have to search in a table data of an advertiser, I need to group by the advertiser according to the most viewed, separated by the date. I wanted to limit the group by, has as? Example table: id…
-
3
votes1
answer2214
viewsOperation of group_concat
I have some questions related to the use of group_concat, more specifically for performance. When using group_concat can’t use limit. // a query retorna todos os ID's select group_concat( id ) from…
-
3
votes1
answer1429
views -
3
votes1
answer3182
viewsDuplicate record - Firebird
In Firebird how to delete duplicate records, keeping only one of them? Someone could help me. I have this select, but it deletes all records, use Firebird 2.1 delete from vendaproduto where…
-
3
votes2
answers7769
viewsLog table using Mysql
How to create a table of log Mysql audit that stores when and what was changed in each record? Mysql provides something that can facilitate this kind of thing?
-
3
votes1
answer46
viewsHow do I get my code to show the highest of each species?
I’m trying as follows (exercise link: SQL Teaching - GROUP BY) SELECT * FROM friends_of_pickles GROUP BY Species; Table: 1 Dave Male Human 180 2 Mary Female Human 160 3 Fry Male cat 30 4 Leela…
sqlasked 9 years, 2 months ago Renoir Reis 508 -
3
votes2
answers8705
viewsCompare items from different tables
I have two tables: Pessoa1 Pessoa2 +----+--------+ +----+--------+ | Id | Nome | | Id | Nome | +----+--------+ +----+--------+ | 1 | Maria | | 3 | Maria | | 2 | João | | 4 | João | +----+--------+ |…
-
3
votes1
answer28159
viewsselect only by month of a particular column - mysql
Well I want to select with the condition that such column has determined month, and only brings results this month. I was doing this, but it didn’t work out. SELECT * from funcionarios where…
-
3
votes1
answer6731
viewsCompare Current Line to Previous
I want in a "Test" column to define the value "S" for only in the first row of a given "code" and all the others to define the value "N" and so successively for all other codes in a SELECT, I am…
-
3
votes3
answers100
viewsWill I lose my databases if I update SQL Server 2012 Express to Standard?
I have installed an instance 2012 Express, I need to update to the Standard, but to update I need to make sure that there will be no changes in the databases.
-
3
votes2
answers222
viewsSQL Contar ROWS
Good! I have two tables: A: PRENUMERE (ID), DATE, STORAGE, TYPE B: Autoreg (ID), PRENUMERE, PRODUCT And I wanted to have a result like: Totalcombustible, Totalloja, Misto Where the Fuel is when the…