tricky SQl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikael

    tricky SQl

    Hi all, i have some problem to solve a sql-query. (Out off topics? I don't
    know.)
    I have a site (a community) with a lot of members. A member
    who are logged in om my site can search for other members. A logged in
    member can block any other member out.

    I have these table. As u can see in blocklist Table member 100102 have
    blocked member 100100 out.
    My question now is. How should i write my sql question.

    I use a session variable session("member No") so i know who performing the
    search.

    so something like this...
    Select all members from memberTable but not those who have me blocked out...

    The members who have me blocked should not be in the result.


    Table Member
    id memberNo Nicname phone
    1 100100 perea 123432
    2 100101 lotta23 34342
    3 100102 berta 23211


    Table blocklist
    id memberNo blockedMemberNo
    3 100102 100100

    Hope u can help out
    Regards Mikael



    ..


  • Hans

    #2
    Re: tricky SQl


    Something like this (set currentMemberNo from you cookie, session variable
    or where you store the value)

    Select memberNo from Member where membeerNo not in (select blockedMemberNo
    where memberNo='" & currentMemberNo & "')"

    If you don't want yourself back either you can add an extra criteria in the
    where clause memberNo<>'" & currentMemberNo & "'"

    Regards
    /Hans


    Comment

    • Hans

      #3
      OOps yet another typ

      ooh my good yet another typo. Forgot the from clause in the subselect. I
      hope you get the picture anyway (I bet there are more typos in there...) ;-)

      Select memberNo from Member where membeerNo not in (select blockedMemberNo
      from blocklist where memberNo='" & currentMemberNo & "')"


      Regards
      /Hans


      Comment

      • Hans

        #4
        Re: tricky SQl

        If memberNo is numeric the where clause should be something like
        memberNo<>" & currentMemberNo & ")"
        instead of
        memberNo<>'" & currentMemberNo & "')"

        (no quotes around the value).
        Regards
        /Hans


        Comment

        • Mikael

          #5
          Re: tricky SQl

          Hi Hans and thanks for helping out here...
          I have construct a sql question with your help...But it works for 50 %.
          The member who block another member can't find that blocked member any more.
          Thats perfect..but
          when that blocked member logg in and search he can still find that person
          who have blocked him out. That
          is not right. A member that block another member has been terrorised or some
          thing from that member. So the
          member who has been blocked should not find the member who haved blocked him
          in his searchresult.

          Hope u have time for a followup?

          strSQ ="Select * from member, profil where member.medlemsN r=profil.medlem sNr
          AND member.medlemsN r not in
          (select sparrad from sparrlista where medlemsNr=" & session("medlem sNr") &
          ")"

          Regards mikael



          "Hans" <hansb@sorry.no spam.com> wrote in message
          news:u%23Zyt7lF EHA.580@TK2MSFT NGP11.phx.gbl.. .[color=blue]
          >
          > Something like this (set currentMemberNo from you cookie, session variable
          > or where you store the value)
          >
          > Select memberNo from Member where membeerNo not in (select blockedMemberNo
          > where memberNo='" & currentMemberNo & "')"
          >
          > If you don't want yourself back either you can add an extra criteria in[/color]
          the[color=blue]
          > where clause memberNo<>'" & currentMemberNo & "'"
          >
          > Regards
          > /Hans
          >
          >[/color]


          Comment

          • Bob Barrows [MVP]

            #6
            Re: tricky SQl

            If Hans has solved your problem then you don't need to reply to this.

            In the future, could you please let us know what type and version of
            database you are using.


            Bob Barrows

            --
            Microsoft MVP -- ASP/ASP.NET
            Please reply to the newsgroup. The email account listed in my From
            header is my spam trap, so I don't check it very often. You will get a
            quicker response by posting to the newsgroup.


            Comment

            • Hans Börjesson

              #7
              Re: tricky SQl

              Hi!

              then you need to add an extra criteria.

              sSQL = "Select * from member, profil where member.medlemsN r=profil.medlem sNr
              AND member.medlemsN r not in
              (select sparrad from sparrlista where medlemsNr=" & session("medlem sNr") &
              ") AND medlemsNr not in (select medlamsrNr from sparrlista where sparrad=" &
              session("medlem sNr") & ")"


              The last subselect will fetch all medlamsNr that have blocked the current
              medlmesNr (the one in your session variable) blocked.

              Depending on your database (don't know which one you use? Access?) you may
              combine the two queries with a union like

              Select * from member, profil where member.medlemsN r=profil.medlem sNr
              AND member.medlemsN r not in
              (select sparrad from sparrlista where medlemsNr=" & session("medlem sNr") & "
              UNION select medlamsNr from sparrlista where sparrad=" &
              Session("medlem sNr") & ")"


              I bet there are some typos here once again but this should at least show the
              principle. You should be alright with at UNION here but there also exists a
              UNION ALL (will not remove duplicate records in the resultset) but in your
              case I think you are OK with a UNION.

              Regards
              /Hans


              Comment

              Working...