The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
1answer
46 views

Use if exists in postgresql [closed]

I know about the exists feature, but that does not help me with the given situation. What I want is: Check if some row exists, and if exists then check for an another row if row exists. Here's ...
1
vote
1answer
19 views

How to conditionally raise an error in MySQL without stored procedure

I need to conditionally raise an error, but I can only use a simple statement and no stored procedure. I'd like to do something like this: select case when foo = "bar" then 1 else SIGNAL SQLSTATE ...
1
vote
4answers
42 views

where clause: if this value from col x make sure col y is this value

I feel like this is an easy one for you Experts! I haven't done any kind of Advanced SQL in years. Fundamental question: select * from myTable where ((if col1 = 'this', make sure col2 = ...
2
votes
1answer
66 views

Conditionally join table

I'm new to database design and have designed a database that seems fine for the application but looks like it has a major red flag to me. I have a master table which is then joined to another table ...
0
votes
1answer
55 views

MYSQL testing string field contains another altered string field

I have this table : mysql> desc mytab; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | ...
0
votes
2answers
51 views

Oracle conditional statements

I am making a report, and I am trying to do following: If the value of the field is NULL, output empty string. Another words, I don't need the word "null" to be output to the user, just empty string. ...
1
vote
1answer
72 views

PostgreSQL WHERE clause with two OR'ed conditions, priority to first

I'm storing user data (username, email, password hash) in PostgreSQL, and I can only enforce uniqueness on username. I'd like to let users provide either their username or their email when they login. ...
0
votes
1answer
46 views

What is the correct way of filtering a property by multiple features?

Having the following tables: Property Feature PropertyHasFeature (property_id, feature_id) What is the right way to search properties by specifying multiple features? I want to list all ...
-1
votes
1answer
43 views

How to compare a result of a query to a number? [closed]

I have a query that return selects a table and returns one column with a number, and I want to know if the result is > 0. SELECT * FROM Table WHERE (SELECT amount from Table2) > 0 ...
1
vote
2answers
77 views

Not able to produce table based on conditional select

I would like to achieve something that probably ends up in some kind of conditional select (MS SQL) but I do not know how to. I have tried to simplified my problem to the description below: I have 3 ...
2
votes
1answer
104 views

Why should the most restrictive condition be listed last in the where clause?

The book I'm going through has given a rather poor explanation of why exactlt to place the most restrictive condition last in the WHERE clause. Say that we have Query 1: SELECT COUNT(*) FROM ...
2
votes
1answer
179 views

Search a Redis Database

Imagine having a tun of hashes in a Redis Database, each representing a user object. How would you get the user with for example the lowest registration date? The user where ts_registered is the ...
0
votes
1answer
38 views

Combine 2 SQL Queries

How do I combine these 2 queries? select a, b, c from MY_TABLE where date < sysdate+1 AND c is NULL order by id select a, b, c from MY_TABLE where date < sysdate AND b is NULL order by id
1
vote
1answer
313 views

Mysql update different fileds set depend on condition

I have two tables "a" : CREATE TABLE `a` ( `id` int(11) NOT NULL AUTO_INCREMENT, `i1` int(11) DEFAULT NULL, `i2` int(11) DEFAULT NULL, `ib` int(11) DEFAULT NULL, KEY `id` (`id`) ) ...
0
votes
2answers
133 views

How mysql process where condition

I have a query like Select * from tbl1 WHERE ( price > 10 AND qty > 200 AND condition=1 AND name like '%abc%') My question is how MySQL will process this? My concern is that I want ...
1
vote
2answers
864 views

Conditional WHERE clause

I have, from what I can tell, a unique question. I would like to know if there's a way to construct a query in which the existence of the actual where clause itself is conditional. I'm writing a ...
2
votes
1answer
2k views

How to export mysql database based on a where condition

I need to export the data and structure of a table but the data must have a specific condition (WHERE status=0 and id>20). How to export mysql database based on a where condition from phpMyAdmin or ...
2
votes
1answer
2k views

Can I mysqldump an entire database while using where='condition' on individual tables?

I have used mysqldump to dump an entire database, However, when I want to use --where=condition", on individual tables, I have dumped individual tables mysqldump --where='condition' mydb table ...
3
votes
4answers
3k views

MySQL : Conditional ORDER BY to only one column

Hello and thanks for taking time to read this question. I am using MySQL, and I want to sort results using ORDER BY to one specific column, but the results must be ordered according an specific ...
13
votes
4answers
17k views

Logical operators OR AND in condition and order of conditions in WHERE

Let's examine these two statements: IF (CONDITION 1) OR (CONDITION 2) ... IF (CONDITION 3) AND (CONDITION 4) ... If CONDITION 1 is TRUE, will CONDITION 2 be checked? If CONDITION 3 is FALSE, will ...