Reputation: 275
Im having some issues getting the result I want from two tables
table #1: history
customer_id | Action
------------------------
217 | buy
------------------------
218 | sell
------------------------
219 | hold
------------------------
table #2: Customers
customer_id | name
----------------------------
217 | Alan
----------------------------
218 | Jan
----------------------------
219 | Rick
I have a really long query now, but essentially I want to add to match the name with the amount. I tried this but it didn't work:
(SELECT action AS action FROM "history` LEFT JOIN ON " customer(customer_id=customer_id)`)
I'm not really familiar with doing queries so any help would be appreciated
Upvotes: 0
Views: 48
Reputation: 6223
You can JOIN tables like this:
SELECT history.action AS Action ,Customers.name AS Name
FROM `history`
LEFT JOIN `Customers` ON history.customer_id = Customers.customer_id;
Upvotes: 0
Reputation: 34416
It should be this:
SELECT h.Action AS action
FROM history h
LEFT JOIN Customers c
ON h.customer_id = c.customer_id
You either need to specify the tables or create an alias with which to associate columns/data.
Upvotes: 2
Reputation: 133360
Is a simple join
select action
from history
left join Customers on Customers.Customer_id = history.customer_id
and you can confirm using
select history.customer_id, Customers.Customer_id history.action , Customers.name
from history
left join Customers on Customers.Customer_id = history.customer_id
Upvotes: 0