Home > mysql > Using queries to retrieve data from connected tables

Using queries to retrieve data from connected tables

January 12Hits:1
Advertisement

What I want to do:

I would like to retrieve all data fields about a Customer(including all data from tables that are related with him (e.g the data fields of the Country & data fields of the referralagent

I'd like my query to take as a parameter the idUser.



Here is my EER Diagram:

Using queries to retrieve data from connected tables



What I tried:

SELECT referralagent.firstName ,referralagent.lastName ,customer.firstName ,customer.lastName ,customer.address ,customer.postcode ,customer.profession ,customer.phoneNumWork ,customer.phoneNumMobile ,customer.phoneNumHome ,country.name ,nationality.name      FROM          customer         INNER JOIN referralagent             ON customer.ReferralAgent_idreferralAgent = referralagent.idReferralAgent         INNER JOIN country             ON customer.countryResidence = country.idCountry         INNER JOIN nationality             ON customer.nationality = nationality.idNationality              WHERE customer.idUser = '7' 

The question:

I'm not confident that what I tried is something that's "correct". Is there any better way to do it?

Tags:mysql, sql

Related Articles

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.869 s.