Question: I have a table `test1` and it has data as shown below:

![enter image description here](https://i.stack.imgur.com/x6E3F.png)

Now i don't want to select records where `days>0 in prod_year 2012` from `test1` table,so i used below query:

```
select * from test1
where id in (select id from test1 where pyear=2012 and 
(days<=0 or days is null)) OR id in (select id from test1 where pyear!=2012);

```

But when explained the above query its showing DEPENDENT SUBQUERY

![enter image description here](https://i.stack.imgur.com/vpeaY.png), 

is there any better way to write this query?

Thanks in advance.

Answer: 
This should do the job:

```
select * from test1 where (pyear=2012 and (days<=0 or days is null)) or pyear<>2012

```
Yes. There is. `UNION` would help you:

```
SELECT * FROM test1 WHERE pyear=2012 AND (days<=0 OR days IS NULL)
UNION
SELECT * FROM test1 WHERE pyear!=2012

```

Some MySQL old versions (less than 4.1, I guess) can't use `INDEX` (which means full scan) when use `OR` on defference columns, even though there is indexed column. In that cases, `UNION` should be used.