Click here to Skip to main content
14,575,478 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a table of 2 columns for my Customer table and 3 columns for my Item table. They have no common columns. How do I join them where there's a condition set to it too? i need to implement a table of all the customer details whose price > 200 but i keep getting duplicates :(

something like this

Customer_id Customer_Name price
1002 Amp 250
1166 Boo 1000

What I have tried:

SELECT cust_id, cust_name, price FROM Customer FULL JOIN Item WHERE Item.price > 200
Posted
Updated 30-May-20 23:22pm
v2
Comments
0x01AA 31-May-20 5:34am
   
I assume the "three field table" you show in the question is the "customer_item" table.
Now show also the two fields of your customer table.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You cannot join two tables if they are not related to each other.
You should have a table between Customer and Item tables, which would for example record the items bought by your customers. For now, both tables are completely unrelated, so there is no way to join them in a sensible way.
Moreover, what does mean the price of a customer? Do you mean the total sum of bought items prices by that customer? In that case, you definitely need a table between Cutomer and Item. This is called a many-to-many relationship, and you cannot model it with only two tables.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100