2010-12-20 5 views
0

Ich brauche Publikationen zu erhalten, die die Länderliste kein Land enthält (Forschung auf IsoCode2)Wie eine Tasche mit Nhibernate abzufragen

Die SQL-Abfrage ist:

select * from pub_head ph 
where not exists 
(select 1 from pub_head_forbidden_country phfc , country c 
       where phfc.pub_head_id = ph.pub_head_id 
       and phfc.country_id = c.country_id 
       and c.iso_code2 = 'CA'); 

Und das Modell:

Ich begann mit SubQueries, aber ich hatte keinen Erfolg, es zu tun.

Danke

+0

Haben Sie die Abfrage in HQL sein könnte tun wollen oder mit den Kriterien api? Und was ist diese pub_head_forbidden_country-Tabelle in der von Ihnen geposteten SQL-Abfrage? – Max

+0

Mit Kriterien API – Martyrian

+0

die pub_head_forbidden_country Tabelle ist wie pub_head_country Tabelle (Entschuldigung für das Kopieren/Einfügen) – Martyrian

Antwort

0

Allergisch zu Joins? Dieses SQL ist sehr schwer zu verstehen.

Bedeutet das?

SELECT * 
FROM pub_head 
WHERE id not IN (
    SELECT phfc.pub_head_id 
    FROM pub_head_forbidden_country as phfc 
    INNER JOIN country AS c ON phfc.country_id = c.country_id 
    WHERE c.iso_code2 = 'CA' 
) 

[Posting als Antwort, weil diese SQL in einem Kommentar schrecklich wäre.]

+0

Ja, ich bin allergisch auf Joins;) – Martyrian

+0

Ist die Abfrage nicht viel semantischer und viel weniger so verwirrend? Oder vielleicht ist mein Gehirn nur schwach und faul. :) [Btw: Ich würde versuchen zu antworten, aber ich habe keine Ahnung, wie ich dein Problem lösen soll.] – ANeves

0

Die Sql wie diese zu

SELECT * FROM pub_head ph 
WHERE ph.pub_head_id not IN (
    SELECT phfc.pub_head_id 
    FROM pub_head_forbidden_country phfc 
    INNER JOIN country c ON phfc.country_id = c.country_id 
    WHERE c.iso_code2 = 'CA' 
)