I have a Mysql table like this:

```
url
---------------
example.com/test.php?id=5
example.com/test.php?id=6&serial=10
example.com/test.php?subsid=7
example.com/test.php?id=7&serial=10&subsid=4
example.com/test.php?subsid=9&serial=10&id=8

```

I want to extract id from the url column. So far I have done the following:

```
select url,substring_index(substring_index(url, 'id=', -1),'&', 1) from thetable

```

But the problem is it gets 7 for the third row too which I dont want. I want to get id only not subsid etc.

One more thing, I want to do it without any PHP.

Thanks in advance.