|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Query - General - Subselecting with WHERE clause from 2 tables?
Hello.
I need to pull data from one table (`tr_ut4`) where the `Fiber ID` is also in two other tables (`afis` and `hvi`). I have can get the data with two seperate queries, but I would like to have it done all at once. These are the two queries that work and will get my data: SELECT * FROM `tr_ut4` WHERE `Fiber ID` = ANY (SELECT `Fiber ID` FROM `afis`) SELECT * FROM `tr_ut4` WHERE `Fiber ID` = ANY (SELECT `Fiber ID` FROM `hvi`) I'm usuing phpMyAdmin. I was trying to use AND to select from both tables, but I can't seem to get the sytax correct. Help. ![]() |
|
#2
|
||||
|
||||
|
you may be able to use a UNION, if MySQL supports it ... something like this
Code:
SELECT * FROM `tr_ut4` WHERE `Fiber ID` = ANY (SELECT `Fiber ID` FROM `afis` UNION ALL SELECT `Fiber ID` FROM `hvi`)
__________________
Come JOIN the party!!! Quote of the Month: Pretension: The downside of being better than everyone else is that people tend to assume you're pretentious. Questions to Ponder: You can be overwhelmed and underwhelmed, but why can't you be simply whelmed? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 |
|
#3
|
|||
|
|||
|
mehere, with your suggested Union query, will selection from tr_ut4 occur if 'Fiber ID' in both 'afis' and 'hvi' OR either?
|
|
#4
|
||||
|
||||
|
either ... the union selects all the records from both tables.
|
|
#5
|
|||
|
|||
|
Re: Subselecting with where clause from two table.
Hi,
I hope that the below SQL query will be very useful for you... Code:
Select * from tr_ut4 where fibreid in (select fibreid from hvi) union Select * from tr_ut4 where fibreid in (select fibreid from afis) Thanks & Regards SakthiMeenakshi.S |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - Subselecting with WHERE clause from 2 tables? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|