Reputation: 1239
If I join two tables in a query that looks:
SELECT m1.id AS reg, m1.name AS name, f.registered AS status
FROM phone f
INNER JOIN members m1 ON m1.id=f.user_id
WHERE m1.status='1' AND f.registered='1'
And then I want to add another 10 user ID's in a array like m1.id IN (014,01284,014829,075090)
that should also be listed in the result of a query. I want to avoid a third table in the query because I already know users from this table that I need.
The point is that the end result contains all the detail's of users get from the members table by ID's listed in phone table and array.
What the best way to do this?
Upvotes: 1
Views: 212
Reputation: 3848
The INNER JOIN restricts all your results to those with a match in the join table, but that doesn't sound like what you want
I think Nanne's answer will work if you change INNER JOIN to LEFT JOIN
SELECT m1.id AS reg, m1.name AS name, f.registered AS status
FROM phone f
LEFT JOIN members m1 ON m1.id=f.user_id
WHERE
(m1.status='1' AND f.registered='1')
OR
(m1.id IN (014,01284,014829,075090) )
Upvotes: 0
Reputation: 64399
Seems a bit trivial, so maybe not what you need, but like this?
SELECT m1.id AS reg, m1.name AS name, f.registered AS status
FROM phone f
INNER JOIN members m1 ON m1.id=f.user_id
WHERE
(m1.status='1' AND f.registered='1')
OR
(m1.id IN (014,01284,014829,075090) )
Upvotes: 1