View Single Post

  #5 (permalink)  
Old 04-18-2007
f.mardini
 
Posts: n/a
Default Re: Problems with a subquery

On Apr 18, 1:25 am, "Duz" <jakov.duze...@fer.hr> wrote:
> I find it difficult to understand this query of yours
> (although, I'm learning SQL for only a few weeks so it must be it :)
> but explain this please:
>


OK, I am trying to achieve the following
Table connections represents a network between users, connected_id and
connectee_id are foreign keys from the users table. Also each link can
be found twice in the connections table (with the connected and
connecdtee reversed)
I am basically trying to get all the connections that are at most
separated by two degrees of separation of a specific user (with id 1
in this case).

> ( SELECT DISTINCT t2.connected_id
> *FROM connections as t1, connections as t2
> WHERE ( t1.connectee_id = 1 ) AND
> **( t1.connected_id = t2.connectee_id ) )
>
> *here, you are usig operator AS to make to tables (t1,t2) from table
> connection...
> ** and still you compare theirs connected_id-s
>


here i am getting all the connections of those connected to id 1

> aren't those, always, the same values?!
> those are copys, right?
>
> and in the first subquery...
>
> ( SELECT DISTINCT t1.connected_id
> FROM connections as t1
> WHERE
> ( t1.connectee_id = 1 ) )
>
> you are just looking for id-s that equal 1?
>
> I would find it much easyer (my-spelling-bad-here?) to make just one query.
> Something like:
>
> SELECT users.*
> FROM users JOIN connections
> ON id=connetee_id
> WHERE connectee_id = 1
>
> But again, I can't really tell what is it that you are exactly tryin to
> do...
>
> (sorry for replying on your email the first time)

no problem :)

f.mardini

Reply With Quote