little SQL Help plz

bdwarr6

Limp Gawd
Joined
Dec 11, 2006
Messages
169
I am having a problem with an sql statement Im trying to get information out of 2 databases where information matches basically the url string is test.php?domain=test.com I want this to grab all the ips its using out of the first table, as shown by the hdnpne_table sql then I want to take those results and get information based on that in the hdnpne_bw statement then display them

problem is I dont have the right syntax to pipe in domain, then I have no idea howto join the 2 sql statements for use of the second one

hdnpne_table
Code:
select * from ips where justification = $_GET['domain']

hdnpne_bw
Code:
select * from bw where ip = "result of above sql"
 
SELECT * FROM BW WHERE IP IN (SELECT IP FROM IPS WHERE justification = $_GET['domain'])
 
A nested select is the way to go (like mikeblas showed). And as always, don't forget to escape any user data (such as GET variables) to defend against ingestion attacks.
 
This sounds like a join statement.

select (whatever columns)
from ips, bw
where ips.ip = bw.ip
and ips.justification = $_GET['domain']
 
Do you actually have 2 separate databases or just 2 tables? Do you really need 2 separate DBs?
 
This sounds like a join statement.
Maybe, but maybe not. A join will return multiple matches; the WHERE IN sub-select will only return a single row where duplicate matches exist in the subselected table.
 
Back
Top