0

Our_user table

 - userid
 - username

Our_user_ext table

- userid
- user_country

Our_user_address table

- userid
- shippingaddressid
- billingaddressid

Our_user_contact_info table

- shippingaddressid - shipping address details - first name,address
- bilingaddresid - billing address details - firstname,address

I need to take username,usercountry,shipping firstname,address,billing firstname,address in single query

Can you please help how to write a single query.

3
  • What exactly is it you want to know? How to write a query? Here are the docs for the SELECT statement: docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/… Commented Sep 15, 2020 at 14:06
  • 1
    How Our_user_contact_info table holding shippingaddressid and bilingaddresid ? Commented Sep 15, 2020 at 14:07
  • 1
    This is extremely basic SQL, I would say it would honestly benefit you more to either sign up for some online course, read an intro book to SQL or, if you're in Uni, ask a teacher, rather than coming to Stackoverflow. I say this because if you're struggling with the requirements for this query, it's a very clear sign that your SQL knowledge is minimal and you won't benefit yourself from our answers. The idea isn't that someone writes codes for you and you copy and paste it in your environment. You need to understand the code you're being given or else the answer is useless. Commented Sep 15, 2020 at 16:21

1 Answer 1

1

Try this below script-

SELECT A.username,
B.user_country,
D.firstname shiping_f_name,
D.address shiping_address,
E.firstname billing_f_name,
E.address billing_address
FROM Our_user A
INNER JOIN Our_user_ext B ON A.userid = B.userid
INNER JOIN Our_user_address C  ON A.userid = C.userid
INNER JOIN Our_user_contact_info D ON C.shippingaddressid= D.shippingaddressid
INNER JOIN Our_user_contact_info E ON C.billingaddressid = E.billingaddressid
Sign up to request clarification or add additional context in comments.

4 Comments

Or replace all INNER with LEFT if the query should also return users who are missing our_user_ext rows or out_user_address rows or our_user_contact_info rows.
LEFT join is appropriate if there are possibilities of missing record in reference tables. But if it is obvious that records are available in all tables, INNER join is fine.
I agree if it's obvious. But it wasn't to me by the scarce info. INNER JOIN can be written as just JOIN without the INNER word. Default is INNER unless LEFT, RIGHT or FULL is used. SQL is verbose enough already so I think we shouldn't add to the pain with unnecessary words :-)
Agreed with you. But I feel it is always better to use INNER for beginners to understand things easily :) Thanks for your input @KjetilS.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.