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.

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.