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.
672,779
questions
0
votes
0
answers
4
views
Why I am getting Missing From Keyword error in the following code?
with ctes as
(
select , count() as sums FROM
Trips join Users
on client_id = users_id
where banned = 'No'
group by request_at
)
select ctes.request_at as 'Day' ,round(count(ctes.id)/ctes.sums,2) as '...
1
vote
1
answer
28
views
SQL not allowing deletion of related data
In SQL I have:
CREATE TABLE Customer(
cust_id INT NOT NULL PRIMARY KEY CHECK (cust_id > 0),
full_name TEXT NOT NULL,
phone TEXT NOT NULL,
...
0
votes
0
answers
10
views
first 2 makes query slower than when I use first 1 in sql query in informix database
I have a query on a huge table (126738484 records) on an informix database server;
this query returns only one record.
when I use "first 1 " in the select statement, it runs quickly but ...
-1
votes
0
answers
19
views
ER_BAD_FIELD_ERROR in SQL
CREATE DATABASE IF NOT EXISTS RAIL;
USE RAIL;
CREATE TABLE IF NOT EXISTS train (
t_id INT NOT NULL AUTO_INCREMENT,
t_rating INT NOT NULL,
t_name VARCHAR(20) NOT NULL,
t_price INT NOT ...
0
votes
1
answer
13
views
laravel Eloquent ::has() QueryException on different connection
I have two databases,
db1 :
users table
db2 :
infos table
Each table I created has a Models, and I set a different connection for each one:
User.php => protected $connection = "db1";
...
-3
votes
0
answers
25
views
Check if a table has any records [duplicate]
Considering a situation to check whether a table has any records or not, Is there any difference in the performance or execution speed among the two following queries? If yes, what is the logical ...
0
votes
2
answers
41
views
Using arrays in `WHERE IN` statements
There are the following table structures and data:
CREATE TABLE t_source_category (
id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
label varchar(255) NOT NULL,
path varchar(255) NOT NULL,
...
-2
votes
1
answer
28
views
Why does this SQL command give the error "Unknown statement type"? [closed]
I'm new to SQL and do not really understand why this:
INSERT INTO users (highscore); VALUES ('1');
gives me an error. Why does this not work?
I'm trying to save my high score in the database so I can ...
-4
votes
0
answers
37
views
Spotting missing (null) rows in a table
I have three tables:
Guests
Meals
Dates
Most guests place three orders a day within a week period which is set up as a CTE with the following code:
with Dates(Date) as
(
select cast(@date1w as ...
-4
votes
1
answer
41
views
How do I split a string with inconsistent data?
I have some imperial distances (miles/furlongs/yards) in a column which I am looking to convert into just furlongs. However, the data is inconsistent. Sometimes there is a furlongs value, sometimes ...
0
votes
0
answers
30
views
How do I generate rows of predefined values from a SELECT statement? [duplicate]
In SQLite I want to return a list that I type in myself (for further left join SQL commands):
ABC
DEF
GHI
Not existing in any table but manually entered strings (like how SELECT 'ABC' returns ABC, ...
1
vote
1
answer
29
views
SQL query to update duplicate data
I had a bug in my code which created a lot of new users with the same email (id was the PK), and this caused my Usage table to save data of the new ID that was created.
User table:
user_id | ...
0
votes
1
answer
23
views
How To use QSqlQuery::bindValue
I have this snippet :
int id = m_AddItemCandidate->getId();
QString s = "INSERT INTO studied_substantives (subst_id, no_singular, no_plural, meaning) ";
s = s + "VALUES(:id,...
1
vote
1
answer
26
views
How to use one PS dataset in a WHERE-OBJECT of another dataset
I have been using PS for about 10 years. Today I am stuck with finding a solution to a problem where I want to have items used in a WHERE-Object loaded from a SQL table. From what I have read, I need ...
0
votes
0
answers
35
views
How can I fix this RLS policy issue with Supabase on .insert()?
I am in the process of creating a habit tracking app and am using Supabase PostgreSQL. I am implementing RLS in the habit table but cannot for all that is good figure out this issue. On the click of ...