Reputation: 331
I want to make a page where I can see who have purchased and who not, and I want make the people who HAVEN"T purchased into a new array. I searched some mysql function, but I couldn't find how to make the both of them. I know it will be like this:
mysql_query("SELECT id, name, organisation_id
FROM bought, organisation
WHERE id = id
)
but I don't know from here on, I think I need to use join function but how can I use this function in the way I want?
organisations who bought something are in the other table.
example:
$peoplewhodidn'tbuy:
1
2
3
4
5
6
$peoplewhodidbuy:
7
8
9
10
11
12
Bought table:
id product | organisation id | name
organisation table:
organisation id | name | type
Upvotes: 2
Views: 173
Reputation: 746
try
SELECT t1.*
FROM organisation t1
LEFT JOIN Bought t2 ON t2.organisation_id = t1.organisation_id
WHERE t2.organisation_id IS NULL
Upvotes: 1
Reputation: 6426
Assuming organisation has the 'people' and bought has the purchases
something like:
select
organisation.id,
organisation.name
from
organisation
where
id in (
select organisation_id from bought
)
would give the buyers
select
organisation.id,
organisation.name
from
organisation
where
id not in (
select organisation_id from bought
)
for the non buyers
Upvotes: 1