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
votes0
answers30
viewsDifference between using COUNT in column and COUNT with "*"
I accomplished 2 querys in a bank where I needed to know the amount of records based on a column but if I change the parameter of COUNT() the results are different. SELECT COUNT(`time`) as 'tempo'…
-
1
votes1
answer50
viewsReturn more than one variable in Jquery/PHP
Being objective, my problem is this: I have a form in PHP/HTML and I am using a self-paced field via Jquery. This form brings the last numbers wagered by the user and redoes the bet with this…
-
1
votes1
answer1113
viewsDifference between INNER JOIN, JOIN and WHERE?
I need to perform a query that return me information according to a certain condition, I have always used the Where for not knowing if he could use another method. So what’s the difference between…
-
1
votes2
answers219
viewsLimit result to random
I use the query SELECT * FROM mpbbolao WHERE eTIME1>=2 LIMIT 1 for example. To receive a query result I use LIMIT 1. Is there any way I can randomize what that "1" result will be?…
-
1
votes2
answers410
views1215 SQL code "Cannot add Foreign key Constraint"
When creating this code always comes the error: 1215 "Cannot add Foreign key Constraint" I’ve tried everything, checked the foreign key restrictions and nothing. Someone can help me? create table…
-
1
votes1
answer116
viewsCreate select to return last time something was non-zero
I have a table called Estoque, where have the columns NOME_PRODUTO, DATA, ,among others. The idea is that when I make one SELECT Using the date as parameter I return all products I had in stock that…
-
1
votes0
answers30
viewsUnderstanding of sysprocesses
I’m using the table sys.sysprocesses in the SQL 2012/2014, to identify through the field CONTEXT_INFO, which user of a particular application is tied to a particular session. I created a function by…
sqlasked 7 years, 9 months ago cardosoluizjr 51 -
1
votes2
answers1006
viewsISNULL in a Case When
I’m making a select using the CASE WHEN in Sql Server, so that the existence of a record is checked, if it exists, it selects in a table, otherwise it selects in another table, but the two can…
-
1
votes1
answer544
viewsHow to perform a double consultation in the Standard?
I have a query in SQL Ansi: select * from payments as P, receipts as R where P.created_at < CURRENT_DATE AND P.updated_at < CURRENT_DATE AND R.created_at < CURRENT_DATE AND R.updated_at…
-
1
votes1
answer603
viewsretrieve all records from the last 12 months including zero
I have my table bud_quotations and I want to retrieve all the records that have been entered in the last 12 months, including the months that have no record. Now the count is not working, always…
-
1
votes1
answer156
viewsHow to troubleshoot "3183" error importing a bank into SQLSERVER 2012
Good afternoon! First of all, I warn you, I’m a layperson. I need to run a local bank on my machine to work on a project. I installed the programs: SQLSERVER Express 2012 SQL Management Studio 2012…
-
1
votes1
answer913
viewsINSERT in two tables based on SELECT
Imagine the following scenario: At a certain point it is necessary to duplicate people and their respective items. If I have the following data: Table Person +----+------------+ | Id | Nome |…
-
1
votes2
answers792
viewsSELECT by word in sql server without using Full Text Index
I need to make a query in a table with the following words: "Today the day got rainy" I need to search for any of these words. For example if you found the word "day", would have to return the…
-
1
votes2
answers120
viewsSum of values taking into account 3 table fields
I have the following table quotations that serves to fetch the totals of various budgets. And each budget has one piece (part_id) which can have several:…
-
1
votes2
answers939
viewsUse foreign key as primary key - Hibernate
I am implementing Hibernate in my project and arrived at a stage where I am having problems to map my entities. I have an entity called Book and would like to create a Stock entity to store the…
-
1
votes1
answer317
viewsSQL counting data from the second table of INNER JOIN, but shouldn’t?
I have 2 tables: sponsors quotas What I need to do is check how many nominees the sponsors have but only count the users who have the record in the table cotas. The SQL I made is as follows: SELECT…
-
1
votes2
answers1223
viewsSQL - Searching for best-selling product in a date range
I’m trying to search with SQL the best selling product within a certain period. For this, I have the table 'conta_products', which has the following columns: id (PK) | conta_id (FK) | producto_id…
sqlasked 7 years, 8 months ago Gabriel Augusto 530 -
1
votes0
answers123
viewsMS SQL Query for JSP
I’m creating a website based on the JSP language but I don’t know how to return a consultation which I did in the MSSQL Server, the same goes below: DECLARE @Nomes VARCHAR(8000) SELECT @Nomes =…
-
1
votes1
answer103
viewsValidate multiple forms at once - Simulated
I’m creating a simulated site and I’m having trouble correcting it, because I don’t know how to validate numerous forms at once. What happens: I have questions that are randomly selected by the…
-
1
votes1
answer326
viewsSelect bestsellers in related table
I have a table pedidos, produtos and another produtos_em_pedidos described as follows: produtos: id | nome pedidos: id | data produtos_em_pedidos: produto_id | pedido_id | quantidade I need to…
-
1
votes1
answer446
viewsSelect a row where a column has an element of a CSV
I have a table in the database with the following structure: +---------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |…
-
1
votes1
answer931
viewsComposite Key Table without repetition
How do I make a table with composite key, but I can’t repeat the combination of values. I want to store FRIENDSHIPS, using a syntax similar to is: tb_amizades id_usuario_um id_usuario_dois SELECT *…
-
1
votes1
answer463
viewsCreate 90-day filter before a period
I need you to bring back the results that completed 90 days within an informed period. For example, I have the ability to do: DT_INICIO_REAL <= (sysdate-90), I will have as a result 90 days from…
-
1
votes1
answer127
viewsDoes not return the amount of records from the Postgresql database
I would like to know the amount of records in my database, but does not return the amount. Look at the records in my database SQL command Select count(*) as contaRegistros from tb_produtos where…
-
1
votes1
answer63
viewsA SELECT that pulls rows from a column (string;string)
Well I need a SELECT that returns all the lines that contain the name "maria", I have in a column the values and I want a select that shows me all the lines that have the word "maria" in that…
-
1
votes1
answer464
viewsMysql: Query Table N:N
Create database Banco default character set utf8 default collate utf8_general_ci; use Banco; create table Cadastrados( Nome varchar(50), Sexo enum('M', 'F'), Matricula varchar(9) unique, Curso…
-
1
votes1
answer36
viewsDoubt in Table creation
Good Night, I am creating a database for an association, where it is necessary to do the renewal every semester. I created a registration table with the members data: create table Cadastrados( Nome…
-
1
votes2
answers1288
viewsHow to create 1:N relationship tables?
I’ve studied databases and understand how to diagram this type of relation, but now that I’m trying to implement this database using sqlite3 and python I’ve seen some problems. I have the following…
-
1
votes0
answers395
viewsJava Hibernate Query (HQL) with foreign key... ERROR!
I need help with my code, I have two tables: -CDF (official register) CREATE TABLE public.cdf( ativo character varying(1) COLLATE pg_catalog."default", reg integer NOT NULL, nome character…
-
1
votes3
answers399
viewsTransforming DD/MM/YY into PHP timestamp
I need the user to enter a date and this date is sent to the database as timestamp, example Insert: 25/12/17 in the field I want it to reach the database as 1514160000 which means "Mon, 25 Dec 2017…
-
1
votes0
answers40
viewsHow to make Linked server with Oracle database for SQL Server 2008 (and considering VPN connection)?
I need to create a Linked Server connection to my client’s SQL Server 2008 database. This Linked Server will be with an Oracle database. My SQL Server 2008 database is in a server of my client. The…
-
1
votes1
answer703
viewsAdd cases to a query
I need to create a query that adds up to 2 cases, but I’m not getting it the way I did. Case the field D3_UM = 'PC', he must add the field D3_QTSEGUM. Case the field D3_UM <> 'PC', he must add…
-
1
votes0
answers45
viewsNormalize database (unpivot columns per month)
Good night, An Excel table with PERVASIVE SQL connection with one column per month, that is, 12 columns. In order to better work the data, I need to transform the 12 columns into only 2: - a first…
-
1
votes1
answer2146
viewsExport SQL query data to Excel
Good afternoon, everyone. I created a database to control the receipt and delivery of cards. The inclusion of the data is done through a form in excel. This form also has the option of consulting…
-
1
votes1
answer22
viewsBecause my project is not being accepted, I am using mysql6.3
create procedure cadastrar_nadador (out nome_v varchar(80),out sexo_v varchar(1),out nascimento_v date,out patrocinio_v varchar(80)) begin insert into…
-
1
votes1
answer1197
viewsDelete Duplicate Records by Group BY
Good morning, Does anyone know if there is a possibility to delete duplicate records as follows: I have a query that brings the result All fields repeat themselves except the NDO field, and…
-
1
votes1
answer41
viewsHow to pass SELECT DB Pervasive parameter
I’m having to work with Pervasive database, so I’m having trouble passing a parameter to perform a SELECT I’ve tried using: DBCmd.Parameters.Add("@inicio", PsqlDbType.VarChar).Value = date_inicio;…
-
1
votes0
answers31
viewsIntegrate Combobox with Tableview QT
I have a table Courses: create table Cursos( ID_curso int not null auto_increment, Nome_curso varchar (50), primary key (ID_curso) )default charset = utf8; And another registered table: create table…
-
1
votes2
answers81
viewsDoubt with Query SQL
I have a stock movement table with the following columns and data: table moves id | operacao | prodinsumo | qtde ---------------------------------- 1 | 1 | 25 | 6 2 | 2 | 10 | 3 3 | 10 | 17 | 1 4 |…
sqlasked 7 years, 7 months ago Laércio Lopes 4,352 -
1
votes2
answers892
viewsPDO - Which is better: columnCount or rowCount?
I’m new to PDO (I was forced to choose between mysqli and Pdo after migrating php from version 5.2 to 7.0) and made a system where the user does the search: $b2 = $_POST['b2']; $busca =…
-
1
votes1
answer922
viewsSave query results to an array
good afternoon! I need to get the results of this query: sql = "SELECT controle.ID FROM controle WHERE BP = '" & controlectform.nmbpbox.Value & "';" And save to an array. Later I’ll do a for…
-
1
votes2
answers99
viewsReturn values less than 10 from a column with Datediff
I need to return values less than 10 in a column with DATEDIFF and others between 10 and 20 of the same column. Someone can help me? SELECT CONVERT(VARCHAR(10), (MAX(REMESSA.DT_USO_FIM)),105) AS…
-
1
votes1
answer491
viewsGroup Mysql output in PHP
I have two tables in my database cad_usuario and the cad_automovel. The User registered in the first table may have several vehicles registered in the second table. SELECT aut.usuario_id, aut.marca,…
-
1
votes2
answers1048
viewsSQL Replace when some variable contains semicolons
I am using this command smoothly to replace class="texto1" for class="texto2": UPDATE tabela SET estilo = REPLACE (estilo,'class="texto1"','class="texto2"') WHERE estilo LIKE 'class="texto1"'; It…
-
1
votes0
answers517
viewsCreating Event in MYSQL to delete records per day
I’m trying to create an automatic event in Mysql so that every 24 hours it runs the following command to delete promotions without admin interaction, where if the end date is shorter than the…
-
1
votes1
answer42
viewsProblem in defining Foreign key
I’m learning now database. I’m not getting why not let me set team_id as Foreign key.…
-
1
votes1
answer394
viewsError in query INSERT INTO
I’m new using Oracle SQL Developer and I’m trying to make the query run but this appearing error, see photo.…
-
1
votes1
answer60
viewsError Calling Up Report
I have an error below, when I call a report, which has a query in the database, I am not able to solve. Give a look at the result has nothing to zero Follows the code: SELECT SD.D2_DOC,…
-
1
votes1
answer422
viewsORDER BY in string date
I have a table in the database, novidades, where I have a column with the name date is being stored as a string in the format dd-mm-yyyy, but I would like to sort by date based on this value, I…
-
1
votes1
answer63
viewsProblem with RAND in SQL
I am using Mysql "5.6.38-log - Mysql Community Server (GPL)" I have a trial that runs every second, and in it has a validation with a RAND: WHERE t.auc_due_time < GREATEST(LEAST(TRUNCATE(12 *…