Results 1 to 3 of 3

Thread: Query help

  1. #1
    Join Date
    Jan 2003
    Location
    India
    Posts
    523

    Unanswered: Query help

    Trying to do some thing like this:
    PHP Code:
    sender (customerID intmsgid int)
    receiver (customerId intmsgid int
    now we store the message sent by a customer in the sender with respect to the msgid
    the table receiver stores the customers who have received a message i.e. the same msgid with the different customerId
    for e.g. if a customer A sends message to customer B it would be saved as


    PHP Code:
    sender 
    customerid  msgid 
    A        12101


    Receiver

    CustomerID  msgid
    B        12101 
    now i want to find out how many senders have received messages from the receivers.
    meaning if A has sent a message to B and whether B has sent a message back to A
    got to find out how many such uses exists in sender table with a message from the receivers whom they had sent a message.

    regards,
    Harshal.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select count(distinct s.customerid)
    from sender s inner join receiver r
    on s.msgid = r.msg.id
    where exists
    (select 1 from sender inner join receiver
    on sender.msgid = receiver.msgid
    where sender.customerid = r.customerid
    and receiver.customerid = s.customerid)

    ... or something like that
    Last edited by r937; 06-14-04 at 05:03.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2003
    Location
    India
    Posts
    523
    Quote Originally Posted by r937
    select count(distinct s.customerid)
    from sender s inner join receiver r
    on s.msgid = r.msg.id
    where exists
    (select 1 from sender inner join receiver
    on sender.msgid = receiver.msgid
    where sender.customerid = r.customerid
    and receiver.customerid = s.customerid)

    ... or something like that

    Thanks rudy u got me going

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •