Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Full-Text Search / November 2006

Tip: Looking for answers? Try searching our database.

fulltext, distinct, order by

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sebastian - 20 Nov 2006 02:44 GMT
I have a problem. I use Constainstable to make a fulltextsearch over 4
tables.
Now I want to order the result set. The problem is that if I insert the
column all_ranks in the Select part I have some double results. That is
because some keywords are 2 times or 3 times related to an expert.

So If I use this statement I have double information:

Select distinct inQuery.all_rank, inQuery.employeeid,
inQuery.firstname, inQuery.familyname, inQuery.Qualifications,
inQuery.Title, inQuery.Profil, inQuery.deptname from experts,
(SELECT  e.EMPLID as employeeid, e.FIRST_NAME AS firstname,
e.FAMILY_NAME AS familyname, e.QUALIFICATIONS AS Qualifications,
e.TITLE AS Title, e.LINK AS Profil,
                     d.NAME AS deptname,  ISNULL(exp_rank.[RANK], 0) +
 ISNULL(key_rank.[RANK], 0)  + ISNULL(area_rank.[RANK],0)
    +  ISNULL(theme_rank.[RANK],0)  as all_rank      FROM  dbo.EXPERTS e
inner JOIN
                 dbo.EXP_KEY ek ON e.EMPLID = ek.EMPLID INNER JOIN
                         dbo.KEYWORDS k ON k.KEY_ID = ek.KEY_ID inner
JOIN
                         dbo.EXP_DEPT ed ON ed.EMPLID = e.EMPLID inner
JOIN
                         dbo.DEPARTMENT d ON d.DEPARTMENT_ID =
ed.DEPARTMENT_ID inner JOIN
                         dbo.AREA_KEY ak ON ak.KEY_ID = k.KEY_ID inner
JOIN
                         dbo.AREA a ON a.AREA_ID = ak.AREA_ID inner  JOIN
                         dbo.THEME t ON t.THEME_ID = a.THEME_ID full
outer join
    CONTAINSTABLE(EXPERTS, *, '"applied" or "computing"') as exp_rank on
exp_rank.[KEY] = e.emplid full outer join
    CONTAINSTABLE(Keywords, *, '"applied" or "computing"') as key_rank on
key_rank.[KEY] = k.key_id full outer join
    CONTAINSTABLE(Area, *, '"applied" or "computing"') as area_rank on
area_rank.[KEY] = a.area_id full outer join
    CONTAINSTABLE(Theme, *, '"applied" or "computing"') as theme_rank on
theme_rank.[KEY] = t.theme_id
        WHERE k.key_id = key_rank.[KEY] or
        e.emplid = exp_rank.[KEY] or
        a.area_id = area_rank.[KEY] or
        t.theme_id = theme_rank.[KEY]) as inQuery
order by inQuery.all_rank desc

What I want to use is a Statement of this kind:

Select distinct inQuery.employeeid, inQuery.firstname,
inQuery.familyname, inQuery.Qualifications, inQuery.Title,
inQuery.Profil, inQuery.deptname from experts,
(SELECT  e.EMPLID as employeeid, e.FIRST_NAME AS firstname,
e.FAMILY_NAME AS familyname, e.QUALIFICATIONS AS Qualifications,
e.TITLE AS Title, e.LINK AS Profil,
                     d.NAME AS deptname,  ISNULL(exp_rank.[RANK], 0) +
 ISNULL(key_rank.[RANK], 0)  + ISNULL(area_rank.[RANK],0)
    +  ISNULL(theme_rank.[RANK],0)  as all_rank      FROM  dbo.EXPERTS e
inner JOIN
                 dbo.EXP_KEY ek ON e.EMPLID = ek.EMPLID INNER JOIN
                         dbo.KEYWORDS k ON k.KEY_ID = ek.KEY_ID inner
JOIN
                         dbo.EXP_DEPT ed ON ed.EMPLID = e.EMPLID inner
JOIN
                         dbo.DEPARTMENT d ON d.DEPARTMENT_ID =
ed.DEPARTMENT_ID inner JOIN
                         dbo.AREA_KEY ak ON ak.KEY_ID = k.KEY_ID inner
JOIN
                         dbo.AREA a ON a.AREA_ID = ak.AREA_ID inner  JOIN
                         dbo.THEME t ON t.THEME_ID = a.THEME_ID full
outer join
    CONTAINSTABLE(EXPERTS, *, '"applied" or "computing"') as exp_rank on
exp_rank.[KEY] = e.emplid full outer join
    CONTAINSTABLE(Keywords, *, '"applied" or "computing"') as key_rank on
key_rank.[KEY] = k.key_id full outer join
    CONTAINSTABLE(Area, *, '"applied" or "computing"') as area_rank on
area_rank.[KEY] = a.area_id full outer join
    CONTAINSTABLE(Theme, *, '"applied" or "computing"') as theme_rank on
theme_rank.[KEY] = t.theme_id
        WHERE k.key_id = key_rank.[KEY] or
        e.emplid = exp_rank.[KEY] or
        a.area_id = area_rank.[KEY] or
        t.theme_id = theme_rank.[KEY]) as inQuery
order by inQuery.all_rank desc

Without the inQuery.all_rank  in the Select part because this part
insert the double information.

This is the error Message:

Server: Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is
specified.

HELP!!!

I can't find a way !!

Thank you very much!

Cheers
Sebastian
Hilary Cotter - 21 Nov 2006 14:45 GMT
Whenever you see an or you should ask yourself is it possible that the
values coming from the or condition could be duplicated.

So if it is a gender thing where there are three cases, M, F, and U
(unknown) there will never be any overlap in the OR condition.

And you can do union alls and get better performance.

If there is an overlap, ie where PK>10 or Gender='M' and you could have
Males with a PK >10 which would be duplicates you would have to do some sort
of funky group by like this:
--I really need to see your data to figure this out though
Select inQuery.all_rank, inQuery.employeeid,
inQuery.firstname, inQuery.familyname, inQuery.Qualifications,
inQuery.Title, inQuery.Profil, inQuery.deptname from experts,
(SELECT  e.EMPLID as employeeid, e.FIRST_NAME AS firstname,
e.FAMILY_NAME AS familyname, e.QUALIFICATIONS AS Qualifications,
e.TITLE AS Title, e.LINK AS Profil,
                     d.NAME AS deptname,  sum(ISNULL(exp_rank.[RANK], 0) +
ISNULL(key_rank.[RANK], 0)  + ISNULL(area_rank.[RANK],0)
+  ISNULL(theme_rank.[RANK],0))  as all_rank  FROM  dbo.EXPERTS e
inner JOIN
     dbo.EXP_KEY ek ON e.EMPLID = ek.EMPLID INNER JOIN
                     dbo.KEYWORDS k ON k.KEY_ID = ek.KEY_ID inner
JOIN
                     dbo.EXP_DEPT ed ON ed.EMPLID = e.EMPLID inner
JOIN
                     dbo.DEPARTMENT d ON d.DEPARTMENT_ID =
ed.DEPARTMENT_ID inner JOIN
                     dbo.AREA_KEY ak ON ak.KEY_ID = k.KEY_ID inner
JOIN
                     dbo.AREA a ON a.AREA_ID = ak.AREA_ID inner  JOIN
                     dbo.THEME t ON t.THEME_ID = a.THEME_ID full
outer join
CONTAINSTABLE(EXPERTS, *, '"applied" or "computing"') as exp_rank on
exp_rank.[KEY] = e.emplid full outer join
CONTAINSTABLE(Keywords, *, '"applied" or "computing"') as key_rank on
key_rank.[KEY] = k.key_id full outer join
CONTAINSTABLE(Area, *, '"applied" or "computing"') as area_rank on
area_rank.[KEY] = a.area_id full outer join
CONTAINSTABLE(Theme, *, '"applied" or "computing"') as theme_rank on
theme_rank.[KEY] = t.theme_id
 WHERE k.key_id = key_rank.[KEY] or
e.emplid = exp_rank.[KEY] or
a.area_id = area_rank.[KEY] or
t.theme_id = theme_rank.[KEY]
group by e.EMPLID, e.FIRST_NAME ,
e.FAMILY_NAME, e.QUALIFICATIONS,
e.TITLE, e.LINK,d.NAME) as inQuery
order by inQuery.all_rank desc

Signature

Hilary Cotter

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

>I have a problem. I use Constainstable to make a fulltextsearch over 4
> tables.
[quoted text clipped - 95 lines]
> Cheers
> Sebastian
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.