user3637325
user3637325

Reputation: 1

joining two queries via DB

I have 2 queries that work separately but I need to connect them so that the any users tagged with the brand id 12 that are at 0 for last used comes into the list.

SELECT * FROM `brands` WHERE `id`='12'

SELECT * FROM `portal_users` WHERE `lastvisit` = '0'

I looked on the internet but didn't find a way to do this.

Upvotes: 0

Views: 37

Answers (2)

Chains
Chains

Reputation: 13157

Need more details in your question (table design, sample data)...

If the tables can be joined on a user id field, then something like this might work:

SELECT
   *
FROM 
   brands b

   INNER JOIN portal_users p
   ON b.user_id = p.user_id

WHERE 
       b.id='12'
   AND p.lastvisit = '0'

Upvotes: 1

apomene
apomene

Reputation: 14389

I guess you are looking for UNION:

SELECT * FROM brands WHERE id='12'
UNION ALL
(SELECT * FROM portal_users WHERE lastvisit = '0')

Upvotes: 1

Related Questions