|
||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read | Login |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
Sorry not nude, I meant nerd
![]() I have a FileTable and a KeywordTable, and a FileKeywordTable to resolve the many-to-many relationship. The FileTable holds info on the FileID, Filename and Filetype (e.g text, powertab). The KeywordTable is just Keyword and KeywordID. The linker table is just FileID and KeywordID. The first part of the SQL query goes: Code:
SELECT DISTINCT FileTable.FileName FROM (FileKeywordTable INNER JOIN FileTable ON FileKeywordTable.FileID = FileTable.FileID) INNER JOIN KeywordTable ON FileKeywordTable.KeywordID = KeywordTable.KeywordID WHERE Code:
(Keyword = 'thrash' AND 'metal') AND DocType = 'powertab' Does anybody have any idea what I've done wrong? I've been trawling teh web but no joy. Any help much appreciated ![]()
__________________
All practise and no theory |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2005
Location: Sheffield
Posts: 5,766
|
hmm, does using "&" or "+" instead of "AND" work?
__________________
www.soundclick.com/geared Evilmags, in his own true words: "I'm a well known pervert who'd stop at nothing to get my hands on anything female". |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
<quick test>
Sadly no ![]() Aren't they concatenation operators in some SQL flavours? I get no hits at all, which would make sense if its searching for 'thrashmetal'.
__________________
All practise and no theory |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
My first thought is that you might need to do a subquery.
I'll see what I can work out. |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2007
Location: Chippenham
Posts: 371
|
My sql programming was an age ago, and it's never really been of interest - so I could be way off mark here. in fact "inner join" is new to me.
(its in my head, but hard to explain) It looks to me that by selecting from the intersection table [FileKeywordTable] which is word|file , however that 'and' works , you're only looking at individual keyword/file correspondancies and wont be able combine conditions. I think some sort of selecting from filetable where exists [select from intersection: keyword = word1 and fileid joins] and exists [select from interstion: keyword = word2 and fileid joins] may be worth looking at. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
Code:
SELECT F.FileName FROM FileTable as F where 'grunge' in (SELECT K.Keyword FROM KeywordTable as K INNER JOIN FileKeywordTable as FK ON FK.KeywordID = K.KeywordID AND FK.FileID = F.FileID) and 'lyrics' in (SELECT K.Keyword FROM KeywordTable as K INNER JOIN FileKeywordTable as FK ON FK.KeywordID = K.KeywordID AND FK.FileID = F.FileID) |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
Although I think my query works, I think you should take arrowodd's use of the EXISTS keyword and rework it. I think it's a better practise for performance reasons.
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
Code:
use FileStoreTest SELECT F.FileName FROM FileTable as F --where 'grunge' in where EXISTS (SELECT K.Keyword FROM KeywordTable as K INNER JOIN FileKeywordTable as FK ON FK.KeywordID = K.KeywordID AND FK.FileID = F.FileID AND K.Keyword = 'grunge') --and 'lyrics' in and EXISTS (SELECT K.Keyword FROM KeywordTable as K INNER JOIN FileKeywordTable as FK ON FK.KeywordID = K.KeywordID AND FK.FileID = F.FileID AND K.Keyword = 'lyrics') |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
Thanks peeps! I'm just making the necessary changes now
![]() It never ceases to amaze me the breadth and depth of knowledge on this forum. We should challenge the Eggheads
__________________
All practise and no theory |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Mar 2005
Location: Sheffield
Posts: 5,766
|
man, we really are a bunch of geeks. Concatentation - thought so in hindsight.
I have patchy knowledge......
__________________
www.soundclick.com/geared Evilmags, in his own true words: "I'm a well known pervert who'd stop at nothing to get my hands on anything female". |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|