What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » SQL/Database Help

SQL/Database Help
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: SQL/Database Help
quote:
Originally posted by toddy
quote:
Originally posted by matty
toddy yours wouldn't work because you are checking if tblFilms.Actor1 = Name1 AND tblFilms.Actor2 = Name1 AND etc.....
you can tell i haven't used a query in a long time :p
It's all good. I test software and a lot of stuff I write database queries for.

There is a better way of doing it I just cannot think of it off the top of my head :)

toddy, you were correct about INNER JOINing the tables here is how you could do it.

sql code:
CREATE TABLE #TEST ( ID INT, Actor1 VARCHAR(50), Actor2 VARCHAR(50), Actor3 VARCHAR(50), Actor4 VARCHAR(50) )

INSERT INTO #TEST
SELECT 0, 'w', 'x', 'y', 'z'

DECLARE @name1 AS VARCHAR(50);
DECLARE @name2 AS VARCHAR(50);

SET @name1 = 'x';
SET @name2 = 'z'

SELECT A.* FROM #TEST A
    INNER JOIN #TEST B ON B.ID = A.ID
        AND (B.Actor1=@name2 OR B.Actor2=@name2 OR B.Actor3=@name2 OR B.Actor4=@name2)
WHERE (A.Actor1=@name1 OR A.Actor2=@name1 OR A.Actor3=@name1 OR A.Actor4=@name1)

Returns:
ID    Actor1    Actor2    Actor3    Actor4
0    w            x            y            z

You just need to join the table on itself on the primary key. However this is more strenuous on the database as you are actually quering all the rows twice.

This post was edited on 03-18-2010 at 08:24 PM by matty.
03-18-2010 08:19 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
SQL/Database Help - by djdannyp on 03-18-2010 at 06:42 PM
RE: SQL/Database Help - by Mnjul on 03-18-2010 at 06:52 PM
RE: SQL/Database Help - by djdannyp on 03-18-2010 at 07:02 PM
RE: SQL/Database Help - by Mnjul on 03-18-2010 at 07:05 PM
RE: SQL/Database Help - by djdannyp on 03-18-2010 at 07:18 PM
RE: SQL/Database Help - by toddy on 03-18-2010 at 07:42 PM
RE: SQL/Database Help - by djdannyp on 03-18-2010 at 07:56 PM
RE: SQL/Database Help - by matty on 03-18-2010 at 08:06 PM
RE: SQL/Database Help - by djdannyp on 03-18-2010 at 08:09 PM
RE: SQL/Database Help - by matty on 03-18-2010 at 08:17 PM
RE: SQL/Database Help - by toddy on 03-18-2010 at 08:17 PM
RE: SQL/Database Help - by matty on 03-18-2010 at 08:19 PM
RE: SQL/Database Help - by toddy on 03-18-2010 at 08:31 PM
RE: SQL/Database Help - by Adeptus on 03-19-2010 at 09:23 AM
RE: SQL/Database Help - by djdannyp on 03-19-2010 at 09:47 AM
RE: SQL/Database Help - by CookieRevised on 03-20-2010 at 10:28 AM
RE: SQL/Database Help - by djdannyp on 03-20-2010 at 10:49 AM
RE: SQL/Database Help - by CookieRevised on 03-20-2010 at 11:23 AM
RE: SQL/Database Help - by Adeptus on 03-20-2010 at 11:26 AM
RE: SQL/Database Help - by djdannyp on 03-20-2010 at 12:38 PM
RE: SQL/Database Help - by CookieRevised on 03-20-2010 at 04:45 PM
RE: SQL/Database Help - by djdannyp on 03-20-2010 at 07:08 PM
RE: SQL/Database Help - by CookieRevised on 03-20-2010 at 10:28 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On