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
-
1
votes2
answers698
viewsJava/SQL Login and Password Validation Issue
I have a problem in the validation of Login and Password, the code is only taken the values of the first line of the database, but when I try to put the values of the other lines it gives error, I…
-
1
votes1
answer966
viewsConvert input to date with oracle
I’m having trouble returning the results of the following query, where I put the variable &mes, if I put '01-Sep-2017' would bring the results I need, but in the dialog box wanted the user to…
-
1
votes1
answer2093
viewsHow to format numbers directly by SQL
Gentlemen, my numbers are coming out without formatting when I perform the select directly at the bank, they are coming out as follows: REALIZADO META 61274436,2090003 80000000,00 How can I make…
-
1
votes2
answers159
viewsHow to separate a letter from a Character in SQL?
I have a variable of type Character Varying(17) and I need to separate one of the characters, for example the third letter, and use it to filter.For example: SELECT * FROM fnord WHERE…
-
1
votes2
answers730
viewsIn an SQL query, bring line values in a single line, field
I need to make one query that brings values of 2 lines in a single Ex: id | valor | banco 000001 | 1000,00 | caixa 000001 | 1000,00 | bradesco I need you to leave like this: id | valor | banco 1 |…
-
1
votes1
answer88
viewsLimit records by number of repetitions
I have a query as follows, and would like to filter by COUNT SELECT COUNT(1) AS QTD, Nome, Cpf FROM Funcionarios WHERE QTD >= 2 GORUP BY Nome, Cpf
sqlasked 6 years, 3 months ago Felipe Siqueira 19 -
1
votes1
answer128
viewsDoubt in sql exercise query
I have the following relationships: The statement of the financial year is: The average grade given by teachers per course discipline Geography in the first half of 2013. Name teacher, discipline…
sqlasked 7 years, 1 month ago William Henrique 589 -
1
votes1
answer55
viewsTwo tables returning only one result
select cliente.codcliente, cliente.dt_cadastro from cliente where cliente.codcliente in ('00000224', '00000170', '00061825', '01009838') order by cliente.codcliente select nfsaidc.codcliente,…
-
1
votes1
answer62
viewsHow to view the columns of a system view in SQL Server?
Well I come from Oracle culture and want to learn about SQL Server. I would like to know how I see the columns of a system view, for example: I tried with sp_help teste.INFORMATION_SCHEMA.ROUTINES…
-
1
votes1
answer387
viewsExit command in PL/SQL
I noticed the command exit works like a break, it stops running the current block and switches to the next one, but which command can stop the whole procedure in PL/SQL?
-
1
votes0
answers45
viewsCreating table schema with pre defined Keywords
Hello, I am creating a table scheme that needs to be well optimized, the reason for that will be tables that will have 3 to 5 million records. The big concern here is with regard to the search, in…
-
1
votes1
answer2413
viewsCopy records from one table to another via select
I am copying the records from one table to another in different databases, but a column in the new table cannot be null and the data coming from the old table are null. Is there a way to put some…
-
1
votes3
answers157
viewsShow comments table
Good morning guys, I wonder if it is possible to list in SQL-SERVER all comments of my "table", not comments of the column, but only of the "tables""
-
1
votes2
answers34
viewsSelect items that do not contain in a second table
I need to select data from a table only when the codigo this table does not appear in a second table. Briefly this would be it. I have the table entregaitem with the following columns…
-
1
votes2
answers165
viewsSearch full month ORACLE
I need to run a report that returns the entire amount for the previous month. He used the following form: where cliente.dtultcomp > trunc (SYSDATE-30) But there are cases of the month being 28,…
-
1
votes1
answer142
viewsCopy table A column to table B sql
Good afternoon Personal, I have two tables and I need to make a SELECT to link the code of the cities that are in table B with the cities in table A. I am using the query: select a.Cidade, b.Cidade,…
-
1
votes2
answers79
viewsMake selection from the results obtained from it
Good afternoon, I have the following table.. *eventos* ---------------------------------------- | id_evento | id_projeto | nome_evento | ---------------------------------------- I need to make a…
-
1
votes1
answer196
viewsError - Display an image saved in the BLOB database
I have a php script that already does the insertion of images in the database, as shown below: <?php session_start(); include "conexao.inc.php"; setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1',…
-
1
votes0
answers36
viewsGrab wordpress post title by SQL
Well, I need something like this: $titulo = get_the_title( $post_id ); update wp_posts set post_content = replace(post_content,'>Episódio','>$titulo Episódio'); I know you’re completely wrong,…
-
1
votes1
answer105
viewsUpdate with SET giving error
I have several UPDATE with practically the same code as this: UPDATE cliente SET Email = '[email protected]' WHERE idCliente = 0000; But some make this mistake: Data truncation: Data Too…
-
1
votes1
answer49
viewsJoin in the database
I am developing a software where the user selects the items from his home, selects how long not to clean them, and at the end fills a form to receive a discount by email and clean the items. All…
-
1
votes1
answer849
viewsError executing query in Postgresql
After executing this query: SELECT p.name as nomerecebe, r.created_at as datarecebimento, r.original_amount as valorboleto, rs.name as statusr, SUM(r.original_amount) as total FROM people as p,…
-
1
votes1
answer1926
viewsHow to create a Primary Key Constraint named in Postgres?
I am proceeding this way to create a table without primary key initially. Then I add a field id serial type and try to create the Constraint to the Primary Key (PK): create table macaco( nome…
-
1
votes1
answer678
viewsHow to create a Foreign key and Unique attribute at the same time?
I would like to know whether there is any way, or how best, of restricting a relationship between two entities, one of which cannot be repeated in this relationship. I have the tables 'Customers'…
-
1
votes1
answer82
viewsSQL: Avoid repeating line and adding values
I have this select: select DISTINCT (clients.name) as nomeempresa, payments.amount_paid as pagamento, receipts.original_amount as recebimento FROM payments, receipts, receipt_status, payment_status,…
-
1
votes1
answer596
viewsDoubt with calculation of the profit margin between values
I have an sql query where I am showing the cost value and sales value of the product, I would like to show the profit margin between cost and sales values, for the quantity of items sold select…
-
1
votes0
answers103
viewsHow to name constraints in Mysql?
I’m trying to name constraints in the MySQL but unsuccessfully, I’m doing it this way: create table if not exists pessoas ( id int auto_increment, nome varchar(30) not null, data_nascimento date,…
-
1
votes1
answer339
viewsSelect Group with PHP
I’m trying to feed a select group with database data, but it’s not working. Someone can see the error? <div class="form-group"> <select class="" name="agencia" tabindex="-1" style="height:…
-
1
votes1
answer388
viewsHow to make a ranking in php?
[Help] ranking in.php file illustrative image: http://prntscr.com/kl11df website image(main page): http://prntscr.com/kl12b3 image of the accounts created for testing: http://prntscr.com/kl13gz I…
-
1
votes3
answers162
viewsSyntax error in Mysql
I was creating a table in Mysql and this error appeared in this code: USE cadastro; CREATE TABLE países( cod_país INT NOT NULL AUTO_INCREMENT, nome_país VARCHAR (30), PRIMARY KEY cod_país ); 1…
-
1
votes0
answers70
viewsPanel to hide PHP user page elements
Good evening, I am making a management system for the company and now appeared an unforeseen requirement that I need to adjust. Inside the administrative page of each customer there are buttons that…
-
1
votes2
answers60
viewsConnection to database on Amazon
Good afternoon, I have a sqlserver database hosted on Amazon, and can’t perform the connection in php, there is some specific way to do this? I tried the connection this way: <?php $servername =…
-
1
votes2
answers1938
viewsHow to Sub Select in SQL
I wonder if anyone can help me because I could not do the command sub select between two tables, someone could help me? I need to pull the name of the book that’s on the table book along with the…
-
1
votes1
answer698
viewsPython Connect Sql With user and "token"
I have an application in Flask and am using Sqlalchemy to access SQL Server. I would like the connection to the database to be made by a generic user and the password is a "token", I thought it…
-
1
votes2
answers79
viewsjoin two tables with date condition
I need to join two tables, being the first presenting all the records contained in it, with the condition that what is in the second table has a lower price with data_ini and dt_fim using the…
-
1
votes0
answers29
viewsproblem with Entityframework
see the return of the script, running directory in mysql, by sqlYog: However, when I run in Visual Studio, the return is different: Serialized result: "TotalMesAMes": [ { "mes": "January", "status":…
-
1
votes1
answer44
viewsRankin in in Mysql
I’m trying to generate a ranking of absences for HR. The record of absences is made in a separate table of the Employee’s registration. I need to bring the list of active employees and the amount of…
-
1
votes2
answers262
viewsSet default value when creating an SQL table
I am studying SQL Language and I am having some problems in the creation of tables, I can not set a default value in a column, whenever I apply, indicates syntax error. Can anyone help me? I have no…
-
1
votes1
answer363
viewsQuery with Procedure, passing table name as parameter in sql server
I would like to create a precedent where I will pass the table name and Table id as parameters, how could I do that? I have my example of how I would like to do DECLARE @NomeTabela VARCHAR(50) =…
-
1
votes3
answers1758
viewsDisplay comma separated results with Mysql
administrador | regiao bruno | 2,3,4 pedro | 1 jose | 5,7 I have an administrator table and a region table, where 1 administrator can manage a region or several. I want to make a query that brings…
-
1
votes1
answer574
viewsDropper my schema tables on Oracle
I am using a Schema in Oracle (sql Developer) and within my schema there are already several tables created that I was using earlier. Now running a new script in this scheme it shows the following…
-
1
votes1
answer31
viewsHelp - Logic Formulation - SQL, PHP, HTML
I have a table in the bank with team registration, where each line corresponds to an employee and their respective team. For example, id_staff, employee 1, Mario 1, Sergio 2, John 2, Joseph I want…
-
1
votes1
answer113
viewsQuery in sql server with different value depending on some variables
Good afternoon I have the following query: select distinct(T.Grupo) 'Grupo', MAX(G.Descricao) 'Grupo', sum(E.QtdCat*S.FactConvEst) 'M2 cativos' from EncLin as E INNER JOIN Stock as s on…
-
1
votes2
answers291
viewsHow to post date and time using datatime type in sql
PHP: $date = new DateTime(); print_r ($date); outworking: DateTime Object ( [date] => 2017-11-07 15:51:26.000000 [timezone_type] => 3 [timezone] => America/Sao_Paulo ) OK so far. Database…
-
1
votes2
answers1722
viewsSelect and delete duplicate records by last update date?
Among the fields in the table there is the name field, the dt_add field which is the date that the record was inserted and dt_update which is the date of the last update of the record. I would like…
-
1
votes1
answer67
viewsHELP - I can’t identify error - PHP and SQL
Hello, I am trying to bring in a table the grouping of all stages and item evaluation per year along with the average scores and weights. I can only bring the last step and item p table, IE, is not…
-
1
votes1
answer267
viewspass external parameters to sqlcmd via batch
I used in the oracle so, I wonder if you have any similar method for the sqlserver (sqlcmd). Batch sqlplus.exe system/123@localhost/xe @..\CRIA_TABELAS.sql "%last_bill%" file . sql SELECT * FROM…
-
1
votes0
answers430
viewsIndentation and line breaking in sql data for html
In short, I created a table with type text in sql so that the user can save some content. However when pulling it back into HTML the formatting is lost. To remedy this I thought of using the tag…
-
1
votes1
answer131
viewsExecutesqlcommand - Update byte - Error
Follows code: var bytes = ConvertTo.Bytes(file); int num = ctx.Database.ExecuteSqlCommand( $"UPDATE dbo.Table" + $"SET Video = '{bytes}' " + $"WHERE id = {Id} "); Follow code to convert: public…
-
1
votes1
answer55
viewsConversion of a LINQ query into methods
The following query in LINQ (with query) below is used to list all vendors that have an account (relationship 1 to 1): from f in fornecedores join c in contas on f.ID equals c.FornecedorID select f…