I am having a problem with this SQL Statement:

```
$sql="SELECT b.FrameNumber, b.BikeCode, IF(b.ProductID = 0, p.FrameNumber) 
   AS FrameNumber 
 FROM BikeStock b LEFT JOIN Purchase p ON b.FrameNumber = p.FrameNumber 
 WHERE b.bikecode = '$bikecode'";

```

I want the SQL statement to work in this way:

```
Select FrameNumber & BikeCode from BikeStock 
THEN IF ProductID(BikeStock) is equal to 0 
     then it will grab the framenumber from the purchase table where bikecode is equal to $bikecode

```

Any Ideas?

Thanks in advance.