PDA

View Full Version : join query problems


sir pannels
03-21-2008, 03:06 AM
hi all,

Just been browsing mysql.com docs for mysql 4.x so that I can perform a mysql join query and have came up with the following ..


SELECT
op.option_id,
op.description,
it.item_description
FROM
item_options AS op,
items AS it
WHERE
op.option_id=1


I have two tables, items and item_options... in both is a item_id field... I want to return any rows from the item_options table where the options_id is 1 (or whatevr no) and then join item table and return the details.. so I did that above, which looks right to me but it just brings back all the rows in items, and for every one displays option_id as 1...

anyone see what I'm doing wrong here? Id rather nail this in one join query than do two seperate queries

many thanks and all the best,

sir pannels
03-21-2008, 04:03 AM
continuing to work on this and have moved on to ..

SELECT items.*, item_options.*
FROM items LEFT JOIN item_options ON items.item_id = item_options.item_id
WHERE item_options.option_id=1

but that just displays an empty result set. doh!

sir pannels
03-21-2008, 04:07 AM
I have done it, I needed RIGHT join :) cheers anyway all