Jump to content

select results from table1 where table.id is in table2


brown2005

Recommended Posts

table 1

 

id

url

 

table 2

 

id

domain

user

 

how can i select records from table 1, where table1.id is in table2.domain and user=1

 

is it

 

SELECT * FROM table1, table2 WHERE table1.id=table2.domain AND table2.user=1

 

or is there a better/faster way?

 

thanks in advance.

 

Link to comment
Share on other sites

if your table2.domain field hold the relationship with table1 (means table1.id = table2.domain) then your first select is the way to do it.. also you can write that in this way per example:

 

SELECT table1.*, table2.id
   FROM table1 JOIN table2 ON table1.id = table2.domain AND table2.user = 1

 

you can also use a LEFT JOIN depending of your data and expected results

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.