MySQL Forums
Forum List  »  Newbie

Re: Need help with join/lookup
Posted by: Peter Brawley
Date: September 27, 2015 11:25AM

The table specs you show don't have primary keys, so they're not really tables at all.

And, it's not clear why you need something called `isinsfdc`.

To find a value in table a based on a value in table b, there needs to be a column in b such that every value of that column in b points at exactly one value of the matching key in a. Such a key column in b is called a foreign key.

So given tables ...

a(aid int, info int)
b(bid int, aid int, foreign key(aid) references a(aid), moreinfo int)

... then if b has the row (1, 1, 65432), a relational database like MySQL guarantees that table a has a row where aid=1, so you could find all its values with

select a.info
from b
join a using(aid)
where b.aid=1;

You'll need to study relational database design. http://www.artfulsoftware.com/dbresources.html has some links to useful intro articles on the subject.

Options: ReplyQuote


Subject
Written By
Posted
September 27, 2015 08:46AM
Re: Need help with join/lookup
September 27, 2015 11:25AM
September 28, 2015 01:00AM
September 28, 2015 11:00AM
September 28, 2015 11:41AM
September 28, 2015 04:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.