If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Recommendations fro search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-12, 16:06
rpiskule rpiskule is offline
Registered User
 
Join Date: Jul 2012
Posts: 2
Recommendations fro search

Hey all.

I am looking for some sort of a database that can do a specific to general search.

So, for example, I want to do a search where:
Company=MegaCorp OR Division=SuperDivision OR Employee=Rob

I want this to return a record for 'Rob'. If that record doesn't exist, I want it to return the record for 'SuperDivision'. If that record doesn't exist, I want the query to return the record for 'MegaCorp'.

Does that make sense?

Thanks!
-Rob
Reply With Quote
  #2 (permalink)  
Old 07-26-12, 16:07
rpiskule rpiskule is offline
Registered User
 
Join Date: Jul 2012
Posts: 2
Also, say I had a record where
Company=MegaCorp, Division=MegaSquad, Employee=Rob

Then the above search would return only the value for MegaCorp...


This is almost like a file system with index.html files, except that it returns the most specific HTML file it can find.
Reply With Quote
  #3 (permalink)  
Old 07-26-12, 17:34
papadi papadi is offline
Registered User
 
Join Date: Oct 2009
Location: 221B Baker St.
Posts: 483
Possibly you want:
Company=MegaCorp AND Division=SuperDivision AND Employee=Rob
OR
Company=MegaCorp AND Division=SuperDivision
OR
Company=MegaCorp

There could be employees named Rob many places and i suspect you want the one that is within the proper company and division.

Suggest you provide more details as to what you want to accomplish other than the the initial post.
Reply With Quote
  #4 (permalink)  
Old 07-26-12, 18:53
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 10,496
virtually any database can do that, but you have to design it and the user interface to to meet that and any other requirements you may have
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 07-26-12, 22:54
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,752
Quote:
I want this to return a record for 'Rob'.
If that record doesn't exist, I want it to return the record for 'SuperDivision'.
If that record doesn't exist, I want the query to return the record for 'MegaCorp'.
Please try...
Code:
...
...
 WHERE Employee = 'Rob'
   OR  NOT EXISTS
       (SELECT 0
         FROM  table_a
         WHERE Employee = 'Rob'
       )
   AND Division = 'SuperDivision'
   OR  NOT EXISTS
       (SELECT 0
         FROM  table_a
         WHERE Employee = 'Rob'
           OR  Division = 'SuperDivision'
       )
   AND Company = 'MegaCorp'
;
If your RDBMS supports RANK function, this also might work...
Code:
SELECT Company , Division , Employee
 FROM (SELECT t.*
            , RANK()
                 OVER( ORDER BY
                             CASE
                             WHEN Employee = 'Rob'           THEN 0
                             WHEN Division = 'SuperDivision' THEN 1
                             WHEN Company  = 'MegaCorp'      THEN 2
                             ELSE                                 9
                             END
                     ) rank
        FROM  table_a AS t
      )
 WHERE rank = 1
   AND
  (    Company  = 'MegaCorp'
   OR  Division = 'SuperDivision'
   OR  Employee = 'Rob'
  )
;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On