soni8010
soni8010

Reputation: 347

select values from table

I have table with below entries.Now I want to select values with timeset_id=0 & timeset_id !=0.

I want to select did_id except did_id=219.Like fields only with timeset_id=0

SELECT * FROM routing_relation WHERE account_id = 36;
+-----+------------+--------+------------+----------+--------------+------------+-------------+
| id  | account_id | did_id | timeset_id | route_id | routing_type | voice_file | voice_file2 |
+-----+------------+--------+------------+----------+--------------+------------+-------------+
| 302 |        36  |    183 |          0 |        8 | ER           |            |             |
| 301 |        36  |    179 |          0 |        7 | ER           |            |             |
| 305 |        36  |    185 |          0 |       11 | ER           |            |             |
| 293 |        36  |    160 |          0 |       35 | ER           |            |             |
| 295 |        36  |    162 |          0 |        1 | ER           |            |             |
| 306 |        36  |    219 |          2 |       12 | ER           |            |             |
| 297 |        36  |    165 |          0 |        3 | ER           |            |             |
| 307 |        36  |    219 |          0 |       13 | ER           |            |             |
| 303 |        36  |    184 |          0 |        9 | ER           |            |             |
| 299 |        36  |    167 |          0 |        5 | ER           |            |             |
+-----+------------+--------+------------+----------+--------------+------------+-------------+
10 rows in set (0.00 sec)

Answer should be like this

| did_id | timeset_id |
|    183 |          0 | 
|    179 |          0 | 
|    185 |          0 | 
|    160 |          0 | 
|    162 |          0 | 
|    165 |          0 | 
|    184 |          0 | 
|    167 |          0 | 

Upvotes: 2

Views: 99

Answers (4)

Dmitrii Cheremisin
Dmitrii Cheremisin

Reputation: 1568

To select only with timeset_id=0:

SELECT * FROM routing_relation where account_id=36 AND timeset_id=0;

To select only with timeset_id != 0:

SELECT * FROM routing_relation where account_id=36 AND timeset_id<>0;

To select timeset_id=0 and not equal to did_id = 219:

SELECT did_id, timeset_id FROM routing_relation where account_id=36 AND timeset_id=0 AND did_id<>219;

It is everything I can say.

Upvotes: 0

Lelio Faieta
Lelio Faieta

Reputation: 6684

Basing on comments your query is the following

SELECT id, account_id, did_id, timeset_id, route_id, routing_type
FROM routing_relation
WHERE account_id = 36 AND timeset_id=0 AND did_id<>219

Try and see if it is what you want. Obviously you can change the list of fields selected to your need.

Upvotes: 0

Syafiq Azwan
Syafiq Azwan

Reputation: 178

Try:

SELECT * FROM routing_relation 
WHERE account_id = 36 
AND did_id != 219 
AND timeset_id = 0

Upvotes: 0

Marek Bettman
Marek Bettman

Reputation: 187

If I understand you right - timeset_id=0 & timeset_id !=0 are making it you want to select all. Then you want to have did_id=219, but only if timeset_id=0.

SELECT * FROM routing_relation WHERE account_id=36 AND NOT ( did_id=219 AND timeset_id<>0)

Upvotes: 2

Related Questions