-3

I have 3 tables. How to display cardNumber and coresponding group based on this situation. I can then create a view and see the card number and which group it belong to.

 **1.ClientCards:**
 1.1cardID
 1.2cardNumber
 1.2relCardTypeID - foreign key of 2.1cardTypeID

 **2.cardTypes:**
 2.1cardTypeID - foreign key of 3.1groupID
 2.2relParrentID
 2.2cardTypeName

 **3.cardGroups:**
 3.1groupID
 3.1groupName
1
  • 3
    There are many questions related to it in StackOverflow.. better search first if it's not available then post a question here. Commented Mar 3, 2017 at 10:25

2 Answers 2

0

Hope your mapped wrong as relParrentID should be foreign key of 3.1 groupID

Try this:

SELECT cc.cardNumber, cg.groupName
FROM ClientCards cc
INNER JOIN cardTypes ct ON cc.relCardTypeID = ct.cardTypeID
INNER JOIN cardgroups cg ON ct.relParrentID = cg.groupID
Sign up to request clarification or add additional context in comments.

4 Comments

yes it is i mapped wrong
hope this query worked for you
yes it works why use inner join and not left join ?
left join better to use. inner join ignores the data where we don't have result in joined tables. stackoverflow.com/questions/448023/…
0
VIEW `card_groups` AS
SELECT 
    `c`.`cardNumber` AS `cardNumber`,
    `g`.`groupName` AS `groupName`,
    `t`.`cardTypeName` AS `cardTypeName`
FROM
    ((`s2_1_cards` `c`
    LEFT JOIN `fxml4_4_card_types` `t` ON ((`c`.`relCardTypeID` = `t`.`cardTypeID`)))
    LEFT JOIN `fxml4_3_groups` `g` ON ((`g`.`groupID` = `t`.`relParrentID`)))

1 Comment

code looks like this:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.