473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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("memberNo") 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

..
Jul 19 '05 #1
6 1294

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
Jul 19 '05 #2
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
Jul 19 '05 #3
If memberNo is numeric the where clause should be something like
memberNo<>" & currentMemberNo & ")"
instead of
memberNo<>'" & currentMemberNo & "')"

(no quotes around the value).
Regards
/Hans
Jul 19 '05 #4
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.medlemsNr=profil.medlemsNr
AND member.medlemsNr not in
(select sparrad from sparrlista where medlemsNr=" & session("medlemsNr") &
")"

Regards mikael

"Hans" <ha***@sorry.nospam.com> wrote in message
news:u%***************@TK2MSFTNGP11.phx.gbl...

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

Jul 19 '05 #5
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.
Jul 19 '05 #6
Hi!

then you need to add an extra criteria.

sSQL = "Select * from member, profil where member.medlemsNr=profil.medlemsNr
AND member.medlemsNr not in
(select sparrad from sparrlista where medlemsNr=" & session("medlemsNr") &
") AND medlemsNr not in (select medlamsrNr from sparrlista where sparrad=" &
session("medlemsNr") & ")"
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.medlemsNr=profil.medlemsNr
AND member.medlemsNr not in
(select sparrad from sparrlista where medlemsNr=" & session("medlemsNr") & "
UNION select medlamsNr from sparrlista where sparrad=" &
Session("medlemsNr") & ")"
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
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lars Plessmann | last post by:
Problem: I try to store data in a objects field and read it out again. Sounds easy, yeah. But its a bit tricky here.... ;-) This is the class Customer.php with some setter and getter functions...
0
by: dracolytch | last post by:
Good day all, Ok, I have a pretty tricky problem that I need some help with. I pass around search query information a fair amount (specifically WHERE statements). Normally, I just rawurlencode()...
1
by: JZ | last post by:
Oracle 9iR2 I have a table: SQL> select * from test; A B C ------------------- ---------- ---------- 01/01/2004 10:00:00 1 1...
4
by: Bung | last post by:
Hi, I have a tricky sql statment I have to write (tricky for me) and I am stuck. I'm having trouble with the following problem. Table1 (Column a, Column b, Column c) Table2 (Column a, Column...
4
by: Angel Cat | last post by:
I have 2 tables joined together by the IDs, People and the pets they own PEOPLE ID NAME 1 JohnSMith 2 JaneDoe PETS ID PET
25
by: PyPK | last post by:
What possible tricky areas/questions could be asked in Python based Technical Interviews?
5
by: Danny | last post by:
Hi there I need help with a tricky problem. I have a 2 dimensional array with qualities such as ball size, ball color, ball weight. Now I have to print out all the possible combinations of...
8
by: pras.vaidya | last post by:
Hi , below given question was asked to me during an interview and i figured it out little tricky . It would be a great help if anyone could solve it. Code : - main() { char...
7
by: NileshKorpe | last post by:
Can you please send me link of some c++ tricky (confusing) questions usually asked in the c++ technical interview. Thank You
1
by: MorrganMail | last post by:
Or at least I find it tricky. :-) Assume we have three tables A, B and C. Table A contains a path and the distance for traveling that path: A (PathId, NodeId, Dist (from previous node)) 1, 1,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.