freehat
freehat

Reputation: 3

SQL Joining tables - To only display rows that have matching parameters

I have 2 tables that I am attempting to join but to only display rows of data based on specific parameters.

Table one: "orders"

Table two: "cash_tracking"

Matching parameters from both tables: "orders.user_id" and "cash_tracking.user_id" and the user_id is 2640

The result I want to see is all the "orders.name" from the "user_id=2640" on a specific shop "shop_id = 7777" and based on a specific register number from the "cash_tracking" table eg. "cash_transaction_reg=444454"

However, when I run my query it shows me every single order on this shop instead of the ones related to the user 2640 on this specific register - 444454

Here is what I have so far:

SELECT orders.name
FROM orders
Inner JOIN cash_tracking
ON orders.user_id = cash_tracking.user_id 
WHERE orders.shop_id = 7777
AND cash_tracking.user_id=2640
AND cash_tracking.cash_transaction_reg=444454

Upvotes: 0

Views: 38

Answers (1)

mbielecki1
mbielecki1

Reputation: 104

You select all orders for user_id, shoud be some join orders.Id = cash_tracking.OrderId

Upvotes: 1

Related Questions