Belltower
Belltower

Reputation: 63

Joining SQL tables and updating values

I'm still trying to join tables and it is not running correctly when I try to run it. Also, the bottom block of input it messed up. I want output to display representing values 1-10. Any help will be appreciated.

SELECT customer_id, cust_first_name
FROM demo_customers
WHERE cust_state= 'VA'
INNER JOIN demo_orders
ON demo_customers.customer_id.cust_first_name=demo_orders.order_id


SELECT order_id
FROM demo_orders
WHERE customer_id= '1'

SELECT order_item_id
FROM demo_order_items
WHERE order_id= '2'

SELECT product_name
FROM demo_product_info
WHERE product_id= <10

Upvotes: 1

Views: 119

Answers (3)

Scotch
Scotch

Reputation: 3226

Try this

  SELECT demo_customers.customer_id, demo_customers.cust_first_name
    FROM demo_customers c
      INNER JOIN demo_orders o
    ON demo_customers.customer_id = demo_orders.order_id
       WHERE c.cust_state= 'VA';

Upvotes: 1

moiter
moiter

Reputation: 162

It's not entirely clear what you are after here, but something like this will provide a join on the 4 tables.

SELECT 
   *
FROM 
   demo_customers
INNER JOIN demo_orders
   ON demo_customers.customer_id=demo_orders.customer_id
INNER JOIN demo_order_items
   ON demo_order.order_id = demo_order_items.order_id
INNER JOIN demo_product_info
   ON demo_product_info.product_id = demo_order_item.product_id
WHERE 
  cust_state= 'VA' 

Upvotes: 1

Micha Wiedenmann
Micha Wiedenmann

Reputation: 20863

demo_customers.customer_id.cust_first_name = demo_orders.order_id

should probably read

demo_customers.customer_id = demo_orders.order_id

Upvotes: 1

Related Questions