Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


SQL JOIN on 2 tables with a list and column ID

SQL JOIN on 2 tables with a list and column ID

SQL JOIN on 2 tables with a list and column ID

How can I Join on KidsData and Fruitdescription table to get Fruit Name from Fruitdescription table rather than hard coding it.
this is what I can get to this far.


<cfquery name="kidsData">
 FROM KidsData K
 LEFT JOIN Fruitdescription F ON F.ID = K.FruitData

Table: KidsData


ID Name FruitData
 1 Candy 100000
 2 Andy  001000
 3 Sarah 001010
 4 Gabby NULL
 5 Jack  000110 
Table: Fruitdescription


ID FruitName 
 0 apple
 1 orange 
 2 kiwi 
 3 banana 
 4 pineapple 
 5 grape 

RE: SQL JOIN on 2 tables with a list and column ID

Looks to me like your Fruitdescription.ID (PK) relates to KidsData.FruitData (FK), but the data in the tables does not look right because in one table you have values 0, 1, 2, ...5, and in another 100000, 001000, 001010, 000110
So, what is the data, what are the columns that relate one table to another?

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: SQL JOIN on 2 tables with a list and column ID

Thanks Andrzejek I understand and have corrected this. I guess i just needed someone to point that out. sorry and thanks.

RE: SQL JOIN on 2 tables with a list and column ID

To me FruitData looks like binary data, bits set, each bit for a fruit. For that to work fruits would need ids 1,2,4,8,16... and no join type would fit that schema. To get n:m relations between kids and fruits you should design a table fruitskidslike (for example) with tuples (kidid, fruitid).

Edit: Well, normal joins would work, but you need unusual join conditions, eg KidsData.FruitData & Fruitdescription.ID = Fruitdescription.ID, besides needing a default value for ID which doubles with each new fruit would limit FruitData to 32 or 64 fruits, depending on using integer or biginteger. IDs like they are would only work as 2^ID.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close