Question: First query 

```
    select id from posts where post_title='abc' || post_title='xyz' order by id desc limit 1;

```

Let's say the returned values are 730 and 735.

Next query

```
    delete from posts where id in(730,735);

```

I want both of these queries to be combined into one statement. How can it be done. Please help

I have tried this one below. it doesn't work. 

```
delete from posts where id in
        (
            select id from posts where post_title='abc' order by id desc limit 1,
                            select id from posts where post_title='xyz' order by id desc limit 1
                        );

```

Answer: 
In my opinion, We must use **IF-EXISTS** clause when executing delete-and-select in one query, because if select returns null, it will throw an exception so try this: 

```
IF EXISTS (SELECT id FROM [Posts] WHERE post_title IN ('abc', 'xyz'))
BEGIN 
     DELETE FROM posts 
     WHERE id IN (SELECT id 
                  FROM [Posts]
                  WHERE post_title IN ('abc', 'xyz') 
                  ORDER BY post_title, id DESC
                 ) 
END

```
As explained [here](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)

**In MySQL, you can't modify the same table which you use in the SELECT part.**

If you absolutely need the subquery, there's a workaround, but it's ugly for several reasons, including performance:

```
delete from posts where id in
(
  select id from (select * from posts)as x 
  where post_title = 'xyz' or
        post_title = 'abc'
  order by id desc
);

```

see [here in action](http://www.sqlfiddle.com/#!2/87db2/1)

just **add limit 1** in your actual code, not supported by the online version.