|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all...
I have two tables: *) TableA with AID as primarykey *) TableB with BID as primarykey and AID as foreignkey I have BID=X. I want all records on A that have the same AID that the TableB on record X. One way is: SELECT * FROM TableA INNER JOIN TableB ON TableA.AID=TableB.AID WHERE TableA.AID IN (SELECT AID FROM TableB WHERE BID=X) But I do not want to use IN as a part of this SQL by optimization reason. Anybody can help me to do it in other way? I was trying using all JOIN forms, but none results (I do not understand all JOIN types yet). Thanks in advance...
__________________
-DdC |
|
#2
|
||||
|
||||
|
Quote:
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
|||
|
|||
|
Yea, you have reason. I wirte wrong table names. The SQL is:
SELECT * FROM TableB INNER JOIN TableA ON TableB.AID=TableA.AID WHERE TableB.AID IN (SELECT AID FROM TableA WHERE AID=X) I want all childrens of a parent who has a particular children with ID=X Thanks |
|
#4
|
|||
|
|||
|
Sorry again. This is the sql:
SELECT * FROM TableB INNER JOIN TableA ON TableB.AID=TableA.AID WHERE TableB.AID IN (SELECT AID FROM TableB WHERE BID=X) I don't want to use IN: Instead prefer joins |
|
#5
|
||||
|
||||
|
isn't that the same as
Code:
select * from TableB where BID=X it looks like you're trying to surmise a real-life example and getting it garbled on the way :/ christo |
|
#6
|
|||
|
|||
|
Yeah, I can't put the real names. But is not the same as
select * from TableB where BID=X This returns one record then I want AID of this record. Later, I want all records in TableB with that AID. It is... Thanks for your soon response |
|
#7
|
||||
|
||||
|
If only I could speak Portugese
![]() Quote:
perhaps an implicit inner join like this would do what you need: Code:
select * from TableA, TableB where TableA.AID='X' andTableB AID=TableA.AID christo (still puzzled) ![]() |
|
#8
|
|||
|
|||
|
I have BID='X' instead of AID='X'
|
|
#9
|
|||
|
|||
|
With two querys or with the IN operator it is easy. But I prefer one query if possible
|
|
#10
|
||||
|
||||
|
lol- how about
Code:
select * from TableA, TableB where TableB.AID='X' and TableB.AID=TableA.AID christo |
|
#11
|
||||
|
||||
|
Quote:
Code:
select otherchildren.*
from TableB X
inner
join TableA parent
on X.AID = parent.AID
inner
join TableB otherchildren
on parent.AID = otherchildren.AID
where X.BID = 'X'
and X.BID <> otherchildren.BID
|
|
#12
|
||||
|
||||
|
Quote:
This returns the same as SELECT * FROM TableB WHERE TableB.AID='X' Quote:
There are only two tables: TableA and TableB |
|
#13
|
||||
|
||||
|
DdC, although my query looks like it's querying three tables, there are only two tables involved
please try my query thank you |
|
#14
|
|||
|
|||
|
See this php script-peice:
PHP Code:
I want to merge the 2 querys just in only one... Thanks |