60 questions from the last 30 days
1
vote
1
answer
9
views
Using subquery as a derived table
I am doing a SQL course and I can't figure out the solution to this question.
In a Car database, there is a Sale table with columns:
SaleID, CarID, CustomerID, LocationID, SalesRepID, SaleAmount, ...
Advice
0
votes
2
replies
120
views
Migrating data to a new database -> On-Prem or Cloud?
At my company, we're starting our data department. Currently, all the information is managed in Google Drive, and knowing this isn't ideal, I want to begin migrating the data to a database. Since we ...
4
votes
1
answer
99
views
Update table 1 columns based on whether the column name exists as a value in another table
I'm trying to figure out an efficient way to do this, preferably as a single MySQL query. I have two tables that look approximately like this (I simplified it as best I could):
table1
CREATE TABLE `...
Best practices
0
votes
9
replies
92
views
Case Expression in Where clause
Isn't it much easier to write this:
SELECT *
FROM your_table
WHERE CASE
WHEN CURTIME() BETWEEN '11:01:00' AND '15:00:00' THEN created_at BETWEEN CONCAT(CURDATE(), ' 11:01:00') AND CONCAT(CURDATE(), '...
0
votes
1
answer
76
views
How to use an incremental DELETE+INSERT without unique_key?
I just started a new position in a company, and they're asking me to migrate their old SQL queries to DBT, the problem is that I'm trying to do a DELETE+INSERT on a range of dates without a unique_key ...
-1
votes
0
answers
82
views
Access lookup using another column value [closed]
I have 4 tables in a MS Access database, namely
Table1 (values - A, B, C, D)
Table2 (values - P, Q, R, S)
Flags (values - Y, N)
Table3 has two columns, TYPE and DESCRIPTION
The TYPE column is a ...
Advice
0
votes
4
replies
93
views
Best database book for 10-thousand-foot flyer?
I'm grokking data analytics as part of the Google DA course, and I realize I'm going to need a bit more about databases than the course teaches.
Any ideas for a great introductory database book? I'm ...
1
vote
1
answer
79
views
How do I version translations while keeping relationships?
Some part of a post has translations:
CREATE TABLE "posts" (
"id" int4 NOT NULL,
"title" varchar,
PRIMARY KEY ("id")
);
CREATE TABLE "...
0
votes
1
answer
100
views
How to optimize SELECT * queries on wide tables?
I'm a MySQL DBA moving to PolarDB IMCI. I know we can force columnstore queries like:
SELECT /*+ SET_VAR(cost_threshold_for_imci=0) */ COUNT(*) FROM t1 WHERE a > 1;
or disable them:
SELECT /*+ ...
Advice
0
votes
4
replies
85
views
How do select ref OID without table object join when type is ref with OID?
Please see following statements and let me know is it possible to
have ref rowid same as other fields in mentioned select without adding
table object join which is t_tab_object here because ref is ...
2
votes
3
answers
150
views
How do you translate (+) joins when they appear across multiple tables?
I have the following query in a legacy Oracle database. (I've simplified it a bit; the real query has a lot of columns that are common across all joins which I've collapsed to one COL_1). I'm trying ...
3
votes
1
answer
182
views
How to recursively inject WHERE clauses into deep subqueries and nested expressions?
I am building a SQL interceptor in Java to implement multi-tenant isolation. My goal is to parse incoming SQL statements using JSqlParser and inject a mandatory predicate tenant_id = '123' into every ...
0
votes
1
answer
89
views
SQLite fails to find newly inserted row [closed]
I'm using SQLite to track Fabrics and create projects that use those Fabrics. Two tables point to each other so Fabrics knows what projects they belong to and projects know what Fabrics are a part of ...
0
votes
1
answer
108
views
Prisma is giving error while trying to migrate it or push to NeonDB
The datasource property url is no longer supported in schema files. Move connection URLs for Migrate to prisma.config.ts and pass either adapter for a direct database connection or accelerateUrl for ...
3
votes
1
answer
116
views
Using REGEXP instead of AND condition
I am writing a query where the user can enter a comma(,) separated value which would be used as an AND condition on a single column - lets say address - for refined search.
For example:
/**
* Search: ...