Sanjana Nair Sanjana Nair - 16 days ago 7
MySQL Question

Query the DB that includes two tables

I am totally new to MYSQL DB. I am trying to query a table that includes another tables two fields.

There are two tables


  1. ORDER DETAILS

  2. CUSTOMER DETAILS



Both are linked using customer_id

I want to get all the data from ORDER DETAILS that has a particular field in ORDER DETAILS plus I want to add it's customer name and employee id with it from customer details.

How is this possible? (I know the basic SELECT * but I don't know anything on JOIN etc please help!

ie. I want all the fields from Order_details + two fields from Customer_details where store_id = "something" (this field is in order_details) - As store_id is not there in customer_details.

Thanks!

Answer

After discussion, this was the final answer:

SELECT order_id,order_details.customer_id,order_name,store_id,customer_name,emp_id from order_details,customer_details where order_details.customer_id=customer_details.customer_id and store_id='12345'