Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [sql]

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.

155,454 questions with no upvoted or accepted answers
23 votes
1 answer
719 views

ODCIAggregateMerge without parallel_enabled

These are quotes from Oracle docs: [Optional] Merge by combining the two aggregation contexts and return a single context. This operation combines the results of aggregation over subsets in order ...
piezol's user avatar
  • 954
19 votes
0 answers
2k views

How can I control the SQL table aliases that Hibernate uses in its generated queries?

tl;dr: Hibernate automatically generates SQL table aliases in its queries like jurisdicti4_ or this_. Here's an example query: SELECT this_.id AS id2_6_3_, this_....
Kaypro II's user avatar
  • 3,300
17 votes
3 answers
3k views

Azure SQL stored procedure ridiculously slow called from C#

Summary: We have two identical databases, one on a local server, one on Azure. We have a C# system that accesses these databases, calling stored procedures. The stored procedures are running very, ...
LMS's user avatar
  • 732
15 votes
3 answers
1k views

Doctrine - Multiple models referencing same id field in another model

I have a Files Model, and Multiple (currently 3) different other Models (Article, Job, Event) that can all have files, that are stored in the Files Model. The problem is that when i generate the ...
smoove's user avatar
  • 3,970
13 votes
2 answers
321 views

SQL update is using old column value

Given this table create table FOO ( ID number(19) primary key, DATE1 DATE default sysdate, DATE2 DATE ); DATE1 is initialized with sysdate when I insert a row, then set to null and then ...
rlovtang's user avatar
  • 5,038
13 votes
1 answer
9k views

How to create an empty array of struct in hive?

I have a view in Hive 1.1.0, based on a condition, it should return an empty array or an array of struct<name: string, jobslots: int> Here is my code: select case when <condition> ...
Joha's user avatar
  • 955
13 votes
0 answers
4k views

Postgresql: partial foreign key?

Is it possible to create a partial foreign key (similar to partial indexes) in general sql / postgresql? I have not found a way to force referential integrity in the following case: Table A is soft-...
Ákos Vandra-Meyer's user avatar
12 votes
7 answers
3k views

Insert row if not exists without deadlock

I have a simple table CREATE TABLE test ( col INT, data TEXT, KEY (col) ); and a simple transaction START TRANSACTION; SELECT * FROM test WHERE col = 4 FOR UPDATE; -- If no results, ...
Jesse's user avatar
  • 6,955
11 votes
1 answer
6k views

How to get all tables detailed information under specific schema in AWS Athena

I am getting the tables detailed information in Hive with the below query, but I am not finding the equivalent in Athena. use schema_name; SHOW TABLE EXTENDED LIKE '*' As part of the output of above ...
JSP's user avatar
  • 547
11 votes
3 answers
4k views

Sequelize query with a where clause on an include of an include

I'm struggling to create a query with sequelize. Some context I have the following models: A Manifestation can have [0..n] Event An Event belongs to one Manifestation (an Event cannot exist without ...
xavier.seignard's user avatar
11 votes
1 answer
7k views

Choose a random row as aggregate function in Hive

I want to group by a column and then select random rows from another column. In Presto, there's arbitrary. E.g. my query is: SELECT a, arbitrary(b) FROM foo GROUP BY a How do I do this in Hive? ...
Leo Jiang's user avatar
  • 25.6k
11 votes
1 answer
12k views

Check if the unique constraint exists and drop it using liquibase

I have a changeset wherein I initially check if the unique constraint exists and then if it does it will drop the constraint. <changeSet author="loren" id="...
Loren's user avatar
  • 1,280
11 votes
1 answer
3k views

How to map native sql results to oneToMany field with SqlResultSetMapping in JPA

For example, say I have the following database tables Building ----------- id name and Room ----------- id roomNo buildingId the Building Java class will look something like @Entity public class ...
duvo's user avatar
  • 1,674
10 votes
1 answer
282 views

How to fetch all rows which will be removed on using cascading delete before delete query

What is the best approach to fetch all the rows, which will be deleted on cascade of primary key? At present we know the list of tables which uses the primary key as foreign key, a simple select query ...
Hari Prasandh's user avatar
10 votes
2 answers
14k views

Missing comma before start of a new alter operation. (near "CHARACTER SET")

Mysql - phpmyadmin What's wrong with this query? ALTER TABLE `invoices` CHANGE `status` `status` ENUM('paid','due','canceled','partial','cheque') CHARACTER SET `utf8` COLLATE `utf8_general_ci` NOT ...
Mohsin Raza's user avatar

15 30 50 per page
1
2 3 4 5
10364