close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Returning rows which appear in both recordsets only.

Thread began 5/07/2013 6:10 am by CraigR | Last modified 5/07/2013 11:20 am by CraigR | 439 views | 4 replies |

CraigRBeta Tester

Returning rows which appear in both recordsets only.

I am recording when emails are sent to members for a particular event, but I want to ensure that if a member id is already stored for that event, it is not stored again.
I have 2 queries set up.
the first query retrieves all of the member ids from the members table whose id does not appear in the eventmember table for (eg) event 15

SELECT MemberID AS MEMID FROM tblmembers
WHERE tblmembers.MemberID NOT IN (SELECT MemberID FROM tbleventmember WHERE EventID = 15)

My recordset returns the rows shown on the left in the uploaded image

the second query retrieves the member ids for all of the members I have selected in my form

SELECT MemberID AS MEMID
FROM tblmembers
WHERE tblmembers.MemberID =1
OR tblmembers.MemberID =6
OR tblmembers.MemberID =4
OR tblmembers.MemberID =5
OR tblmembers.MemberID =13
OR tblmembers.MemberID =2

As you can see, of the selected member ids only member id 2 appears in both recordsets, and this is the only one I want to insert into my table,
I tried combining the 2 queries, but that doesn't give me the result I want.

SELECT MemberID AS MEMID FROM tblmembers
WHERE tblmembers.MemberID = 1
OR tblmembers.MemberID = 6
OR tblmembers.MemberID = 4
OR tblmembers.MemberID = 5
OR tblmembers.MemberID = 13
OR tblmembers.MemberID = 2
AND tblmembers.memberid NOT IN (SELECT MemberID FROM tbleventmember WHERE EventID = 15)

I can see what is wrong,

I wondered is it possible to create the correct syntax without creating a view or a stored procedure ?

Sign in to reply to this post

Jason ByrnesWebAssist

see private message

Sign in to reply to this post

CraigRBeta Tester

OK

Attached Files
jason.sql
Sign in to reply to this post

Jason ByrnesWebAssist

you where close with the last query, you just need to group the OR clauses using perens:

SELECT MemberID AS MEMID FROM tblmembers
WHERE (tblmembers.MemberID = 1
OR tblmembers.MemberID = 6
OR tblmembers.MemberID = 4
OR tblmembers.MemberID = 5
OR tblmembers.MemberID = 13
OR tblmembers.MemberID = 2)
AND tblmembers.memberid NOT IN (SELECT MemberID FROM tbleventmember WHERE EventID = 15);


or you could use:
SELECT MemberID AS MEMID FROM tblmembers
WHERE tblmembers.MemberID IN(1 ,6 ,4 ,5 ,13 ,2)
AND tblmembers.memberid NOT IN (SELECT MemberID FROM tbleventmember WHERE EventID = 15);

Sign in to reply to this post

CraigRBeta Tester

Sorted

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...