Jump to content

Recommended Posts

I have one table with a basic structure of item (varchar), type1 (int), type2 (int) and a second table of types with id (int and name (varchar). The type1 and type2 fields of the first table link to the id of the type table. There will always be one or two types; if there is only one type set the second will be 0.

 

I want to use a join to display item and the two types as text. I checked the forum and found some stuff on aliases. So far I have this query:

SELECT item.name, type1.name, type2.name
FROM item, type type1, type type2
WHERE type1.id=item.type1 AND type2.id=item.type2

 

However this only selects items where both types are set. Is there a straightforward way to fix this query? I've used conditional stuff in Oracle, which I guess probably exists in MySQL, but I'd like to avoid it if there is a simpler way.

 

Thanks to anyone who can help!

Link to comment
https://forums.phpfreaks.com/topic/75590-joining-tables-if-data-exists-in-a-table/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.