Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. self join/ select question

self join/ select question

Scheduled Pinned Locked Moved Database
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elina Blank
    wrote on last edited by
    #1

    Hi, I have the following tables: Item (ItemID) and Item_Keyword(ItemID, KeywordID). ItemID is a primary key in the Item table. In the Item_Keyword table, both ItemID and KeywordID are foreign keys. I need to select such ItemID, that has ALL specified keywords. Thanks in advance for any idea/help

    Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

    E 1 Reply Last reply
    0
    • E Elina Blank

      Hi, I have the following tables: Item (ItemID) and Item_Keyword(ItemID, KeywordID). ItemID is a primary key in the Item table. In the Item_Keyword table, both ItemID and KeywordID are foreign keys. I need to select such ItemID, that has ALL specified keywords. Thanks in advance for any idea/help

      Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      There might be a better way, but this will work: specified keywords='C++','C#','ASP' the where clause of the outer query will need to have the TotalWords = the number of specified keywords (3 in this case).

      select itemid from (select count(*) as TotalWords, itemid
      from item_keyword ik inner join keyword k on ik.keywordid = k.keywordid
      where k.keyword in(**'C++','C#','ASP'**)
      group by itemid) as tbl
      **where TotalWords = 3**

      --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

      E 1 Reply Last reply
      0
      • E Eric Dahlvang

        There might be a better way, but this will work: specified keywords='C++','C#','ASP' the where clause of the outer query will need to have the TotalWords = the number of specified keywords (3 in this case).

        select itemid from (select count(*) as TotalWords, itemid
        from item_keyword ik inner join keyword k on ik.keywordid = k.keywordid
        where k.keyword in(**'C++','C#','ASP'**)
        group by itemid) as tbl
        **where TotalWords = 3**

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        E Offline
        E Offline
        Elina Blank
        wrote on last edited by
        #3

        Thanks, I cam up with the similar solution. My concern is, that if there are 3 keywords, say **'Java'**,'C#','ASP', this query will still select it, or wouldn't it?

        Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

        E 1 Reply Last reply
        0
        • E Elina Blank

          Thanks, I cam up with the similar solution. My concern is, that if there are 3 keywords, say **'Java'**,'C#','ASP', this query will still select it, or wouldn't it?

          Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          Elina Blank wrote:

          My concern is, that if there are 3 keywords, say 'Java','C#','ASP', this query will still select it, or wouldn't it?

          I don't understand the question. Please clarify.

          --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          E 1 Reply Last reply
          0
          • E Eric Dahlvang

            Elina Blank wrote:

            My concern is, that if there are 3 keywords, say 'Java','C#','ASP', this query will still select it, or wouldn't it?

            I don't understand the question. Please clarify.

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            E Offline
            E Offline
            Elina Blank
            wrote on last edited by
            #5

            Sorry, you are absolutely right! It works, thanks a lot!

            Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups