| Author |
Topic |
|
kabucek
Starting Member
7 Posts |
Posted - 2008-10-14 : 10:31:10
|
| hello @LLis it possible to make a query like this?- providing names of table1 & table2.- display data from table1 where userID in table1 is the same as userID in table2 ?is this possible ?Thanks |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-14 : 10:33:15
|
yes its called inner join. select a.* from table1 a inner table1 b where a.userID = b.userID |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2008-10-14 : 10:47:51
|
quote: Originally posted by hanbingl yes its called inner join. select a.* from table1 a inner join table1 b where a.userID = b.userID
|
 |
|
|
kabucek
Starting Member
7 Posts |
Posted - 2008-10-14 : 10:49:44
|
| thanks,what about if i want to do query2 based on the results of query1 ? |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2008-10-14 : 10:51:37
|
quote: Originally posted by kabucek thanks,what about if i want to do query2 based on the results of query1 ?
select b.* from table1 a inner join table1 b where a.userID = b.userID |
 |
|
|
kabucek
Starting Member
7 Posts |
Posted - 2008-10-14 : 10:58:32
|
| thanks,i got this with this command:SELECT `first`, `last`, `street1`, `street2`, `city`, `state`, `zip`, `emailAdr` FROM `table1`, `table2` WHERE table1.userID = table2.userID- but what if i want to do another query based on the results of previous query ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-14 : 11:05:43
|
| another query? what should you return in that based on first? |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-14 : 11:10:37
|
quote: Originally posted by karthik_padbanaban
quote: Originally posted by hanbingl yes its called inner join. select a.* from table1 a inner join table1 b where a.userID = b.userID
lol thanks, i didn't get my coffee this morning |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2008-10-14 : 11:13:14
|
quote: Originally posted by kabucek thanks,i got this with this command:SELECT `first`, `last`, `street1`, `street2`, `city`, `state`, `zip`, `emailAdr` FROM `table1`, `table2` WHERE table1.userID = table2.userID- but what if i want to do another query based on the results of previous query ?
you want some thing like this??????select * from table1 where userid in (select userid from table2) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-14 : 11:29:18
|
| better to use exists than inselect * from table1 t1 where exists (select * from table2 where userid=t1.userid) |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-14 : 11:51:38
|
quote: Originally posted by kabucek thanks,i got this with this command:SELECT `first`, `last`, `street1`, `street2`, `city`, `state`, `zip`, `emailAdr` FROM `table1`, `table2` WHERE table1.userID = table2.userID- but what if i want to do another query based on the results of previous query ?
You mean something like:SELECT `first`, `last`, `street1`, `street2`, `city`, `state`, `zip`, `emailAdr` FROM `table1`, `table2` WHERE table1.userID = table2.userIDand first = 'John' and last = 'Smith' ??? |
 |
|
|
|