Questions tagged [condition]
The condition tag has no usage guidance.
77
questions
0
votes
0
answers
86
views
Oracle 19c - Multiple If Conditions
create or replace TRIGGER trigger_name
...
...
BEGIN
IF SYS_CONTEXT (...) IN (...) THEN
IF SYS_CONTEXT (...) NOT IN (...) THEN
IF SYS_CONTEXT (...) NOT IN (...) THEN
INSERT INTO owner.table_name (...) ...
0
votes
1
answer
668
views
MySQL Trigger to prevent update in one table if particular data is available in another table
I need a MySQL trigger that can prevent update of a particular column data, if some specific data is available in another table.
I have two tables product and sales.
Product
Sale
I need to prevent ...
1
vote
2
answers
80
views
Applying conditional statement in Oracle DB
In the Oracle DB there are three tables, see below.
Table: 'People'
Table: 'Dogs'
Table: 'Cats'
Here is a Fiddle with data to test : http://sqlfiddle.com/#!4/d7cb4
Depending on the result of a ...
1
vote
1
answer
317
views
Splitting up a few big tables into multiple ones and avoiding empty tables
I am in the process of restructurizing and unifying a large database in PostgreSQL. One part of this is to split up some large tables into smaller ones according to their value in 'key'. The function ...
0
votes
0
answers
21
views
Do most real world join conditions involve no more than 2 columns?
In the database application I have worked on, all join conditions are binary, like
select * from A join B join C on A.id=B.id and B.orderno = C.orderno
Each condition, separated by "and", ...
0
votes
1
answer
45
views
Stuck at inserting records into MariaDB conditionally
I know about insert ignore. That's of no use, because MariaDB does not consider NULL to be part of the uniqude index.
Therefore I have to use if ... else.
But this code does not run:
select *
from ...
-1
votes
2
answers
124
views
How to conditionally pick a row based on status value?
I want to select all available and bought packs. An user can open two pages to buy one pack, this results in two rows in the payment table. One gets status 'Pending' and the one that is bought gets ...
0
votes
0
answers
38
views
using lead() to modify next row data
So I have some data like this:
And what I would like to do is modify the WorkDate using the following logic
if lead(EndTime) = StartTime
then lead(WorkDate) = WorkDate
So for example R3 WorkDate ...
0
votes
1
answer
166
views
Fetch all rows and leave column value empty if no equality match
I have a query where I want to fetch all rows where the value in column x is between 400-600.
Including in this I want a matching column value from antoher table.
But I want all 200 rows between 400 ...
0
votes
3
answers
410
views
A flag (indicator) that shows for each row which conditions was used to select it
Suppose I have the table foo. I want to filter the rows of this table using different conditions (cond_1, cond_2, ..., cond_n - the order is important) combined in a disjunction, i.e.:
SELECT * FROM ...
0
votes
1
answer
701
views
Create a trigger to fill a field according to acondition in sql
I want to create a trigger to fill a field according to acondition as below description
For example:
I have a table for all insps that have attachments named: “inspectionAttachments” and I have ...
1
vote
2
answers
2k
views
Set column values based on condition statement
I want to add values to a new column based on: if board_stage is less than alight_stage then service_direction equals 1, to indicate Inbound; if not, then service_direction equals 0, indicating ...
2
votes
2
answers
57
views
Where Clause for Results Appearing after Occurence
I'm wondering if it's possible to find records that only appear after the first occurrence of a where clause. I'm currently using PostgreSQL for this example but something not PostgreSQL specific ...
0
votes
1
answer
48
views
return field name and number of rows which meet condition in one sentence
I have a table in postgres with 10 fields, and need to check for certain values in 3 of them, then return the field name which met the condition and the number of rows in each field.
So it's something ...
2
votes
1
answer
900
views
How to filter table 2 before joining to table 1 so that the result still includes all of table 1, even if no match in table 2?
The following returns all rows from table 1 where post_type = dlm_download. It groups like values from table 2 by the matching column in table 1 so that each row in table 1 has a maximum of one ...
0
votes
1
answer
90
views
Prevent failure in conditional insert in mysql database
The infrastructure of our system looks like this.
An AWS lambda function receives requests such as (accountId, .....). It creates an entry in the MySQL database using a newly generated UUID as caseId....
-3
votes
2
answers
80
views
Multiple statement conditions using OR AND within the query
I have this survey table and I'm trying to gather the information of userid
who answer Strongly agree to the question of I'm trying to watch my
weight OR I love drinking Coffee Black AND must have ...
4
votes
1
answer
220
views
Conditional selection in FROM clause
I have two tables:
parent with columns identifier (pkey) and period;
child with columns identifier (pkey), parent_identifier and period.
There are additional columns, but I did not list them here as ...
0
votes
0
answers
140
views
Condition table theory
Is there a good way to create a "table of conditions"?
I have a huge table, where 4-5 columns are considered in a set of rules, and based on those columns default values must appear in other columns. ...
0
votes
1
answer
625
views
Conditional Join in DB2
2 tables are given
Table T_PRICE
P_Price P_Type P_Route
15 red long
10 long
5 small
Table T_ROUTE
R_Type R_Route
blue long
red ...
-2
votes
3
answers
838
views
Can a `Select` Subquery be conditionally returned? [closed]
Is it possible in Postgres to return a column(Resulting from a subquery) only when a condition matches?
Query:
SELECT
(SELECT NOW()) AS FIRST,
(SELECT NOW()) AS SECOND
Outputs:
| first | ...
4
votes
1
answer
345
views
Does the "don't use errors for flow control" axiom apply to postgres?
In traditional programming there is an axiom that states, "do not use errors for flow control". A general example is to throw an error then catch the error instead of using an ordinary conditional ...
0
votes
2
answers
59
views
Get slave status using sql query inside if-else condition
How can I stop the slave if it is already running using sql query statements only?
So far I tried to do something like below but getting sql syntax error. I think it is due to the borders of result ...
0
votes
1
answer
1k
views
perform multiple conditional join on multiple tables
I have a situation where I need to get result based on conditional joins
For example,
SELECT
CGI.SALES_BRAND_BSNSS_ID,
CGI.SALES_BRAND_CD,
NVL(MTRX. matrix_score_cd,'RV1') ...
3
votes
3
answers
246
views
How to use IN clause in sql server so that it selects everything if nothing is provided for its list argument?
Assume I have a sql query like this
SELECT * FROM TABLE where country in ('USA', 'UK')
This query works as expected that is it selects all rows where country column is either 'USA' or 'UK'. Now ...
0
votes
2
answers
168
views
Postgres - Only allow insert if TWO columns match with a separate table
I have three tables: a users table, a books table, and a chapters table.
Each book has an id called identifier_id (for good business reasons that I cannot work around). This id is guaranteed to be ...
1
vote
1
answer
548
views
In where clause, does MySQL continue checking conditions if first condition before AND falsy
I have a question about and AND inside a where clause of a query. Within the where clause, I have a subquery but it is after a few other, row value conditions, like validated = 1 AND (subquery). I ...
1
vote
1
answer
728
views
IS NOT DISTINCT FROM vs row-wise equality with =
Looking at the below query,
SELECT null IS NOT DISTINCT FROM null AS indf,
null = null AS eq;
indf | eq
------+----
t |
From this we can see the result of the IS NOT DISTINCT FROM is true, ...
1
vote
1
answer
2k
views
MySql sort conditional based on column values
I have a table with products where there's a column for price and stock.
I want the products to be display sorted by the following rules:
All products with price = 0 go to the bottom;
Then the ...
1
vote
0
answers
44
views
How can I auto_increment main and sub category conditionnaly?
So I have a table of items as so
|mainCtgry |subCtgry|
---------------------
| 1 | 1 |
---------------------
| 1 | 2 |
---------------------
| 1 | 3 |
-------------...
0
votes
1
answer
2k
views
Conditional where for postgres stored procedure
I want to create a conditional where clause using a PostgreSQL stored procedure.
This is my original stored procedure :
select distinct
t.serialnumber as sn,
t.productid as tid,
...
2
votes
2
answers
579
views
In what direction SQL Server WHERE clause conditions are checked?
I have this query:
SELECT RCodeID as 'ListItemID',
RCode as 'ListItemName'
FROM RCode
WHERE RCode not like '%,%'
AND ISNUMERIC(RCode) = 1
AND CAST(RCode as int) >= CAST(@...
3
votes
0
answers
6k
views
How to apply a condition on "count over partition"?
I'm using Oracle 11g.
Assuming multiple consecutive entries (sorted by datetime) with the same place_id represent a single visit.
With this table:
datetime_id | user_id | place_id
and I want to ...
1
vote
1
answer
12k
views
If else statement on join query
i am working with a Postgresql database
having two tables:
professionals[professional_id,user_id,account_id]
users[user_id email]
accounts[account_id email]
professionals
[professional_id,...
0
votes
1
answer
124
views
MySQL select all records unless user must be present in favorites
I am having trouble to find the best solution for the following problem;
Description: I want to select all records from an items table, unless it is for favorites only, in that case the user must be ...
11
votes
2
answers
16k
views
Conditional string concatenation in PostgreSQL
I have a table parcels which currently contains the columns owner_addr1, owner_addr2, owner_addr3. Sometimes, one or both of the latter two fields is empty. I want to combine them into a single new ...
6
votes
2
answers
11k
views
How to use a conditional ORDER BY in MySQL?
I have the table courses where we have some fields and also the field course(string), favorited(bool), favoritedDate(dateTime), dateUpload.
The teacher uploads the course and this date is stored in ...
-1
votes
1
answer
37
views
If true then insert event [closed]
I have an insert statement that inserts events into a table. I need it to NOT insert if these events contain specific words or even specific username executing the event. Thought this would be easy ...
0
votes
1
answer
1k
views
SSAS Calculated Member Conditional Count
I have a table representing Accidents and a column with Accident Severity ranging from 'Slight' to 'Fatal'. I want to create a measure counting Fatal Accidents depending on other columns on the ...
4
votes
1
answer
20k
views
How do I select arrays that are not empty?
Why is this so tricky, what is token set to that it isn't equal to null nor an empty string?
SELECT lexemes
FROM ts_debug('This is a title')
WHERE alias = 'asciiword';
lexemes
---------
{}
{}
{}...
2
votes
1
answer
584
views
Matching multiple rows in a MySQL database
A custom built eCommerce store has the following two tables:
orders
| order_id | user_id | amount | shipping_info | date_time |
|----------|---------|--------|---------------|--------------...
1
vote
1
answer
193
views
Is it possible to switch queries based on an input in mySQL?
Is there a way to switch queries based on values? Let's say I have the below query:
select pdate as 'Payment Date', ROUND(@sum_amount := @sum_amount + `amount`) AS 'Total Amount' from
(
select @...
16
votes
2
answers
5k
views
NOT (a=1 AND b=1) vs (a<>1 AND b<>1)
In the WHERE clause of a SQL query I would expect these two conditions to have the same behavior:
NOT (a=1 AND b=1)
vs
a<>1 AND b<>1
The first condition behaves as expected, and while ...
2
votes
2
answers
399
views
If a record does not exist set a value
I am struggling with my statement in PostgreSQL. I have 3 tables:
tbl - flags (labeled as a)
a.email
tbl - accounts (labeled as b)
b.id
b.email
tbl - foo (labeled as c)
c.account_id
c.total
My sql ...
2
votes
2
answers
1k
views
Updating whole table once, criteria : column_name and each value
I have a table with 606 rows. The first column is simply ID (starting at 1 to 606), the next column names are name1, other1, name2, other2, etc. until name100, other100.
I'm trying to create a query ...
0
votes
2
answers
4k
views
How to combine "SELECT" and "REPLACE INTO" when combining two MySQL tables into another?
I've got data with measurements split between two different tables, but the data doesn't need to be present in both:
mysql> SELECT * FROM t1; mysql> SELECT * FROM t2;
+----------------...
1
vote
0
answers
113
views
Tracking Changes
I have an SSRS report with hierarchies for the company and their contact info. As these hierarchies change overtime, is there a way to track what has changed since the last run(run on a weekly basis)? ...
2
votes
1
answer
1k
views
Conditional relationships? One-to-many relationship using a pivot table for only a type of entity
I have the following tables:
users:
- id
- name
- user_type_id (references id on user_types)
neighborhoods:
- id
- name
homes:
- id
- house_number
- neighborhood_id (references id ...
11
votes
4
answers
5k
views
Invert a Boolean expression which can return UNKNOWN
Example
I have a table
ID myField
------------
1 someValue
2 NULL
3 someOtherValue
and a T-SQL Boolean expression which can evaluate to TRUE, FALSE or (due to SQL's ternary logic) UNKNOWN:
...
0
votes
2
answers
142
views
SQL With Multiple Condition and Column
I have 3 tables:
Employee
+----+--------------+--------------------+----------------+
| Id | EmployeeName | EmployeePermission | Position |
+----+--------------+--------------------+------------...