WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   SQL Statement (http://www.wcm.at/forum/showthread.php?t=145544)

reichr 23.09.2004 13:33

SQL Statement
 
hy!

habe 2 tabellen

tab1
artnr,...

tab2
artnr,...

nun möchte ich alle artnr von der tab2 rausbekommen die
in der tab1 nicht vorhanden sind!

wie stell ich das am besten an??

pc.net 23.09.2004 13:44

Code:

select t1.artnr
from tab1 t1
where not exists (select 1
                  from tab2 t2
                  where t2.artnr = t1.artnr)
;


reichr 23.09.2004 14:40

mercy ;)

that`s great :)

heli2sky 23.09.2004 16:26

wo wir grad dabei sind... :D

ich hab eine suche, die in 3 schritten sucht (für ein lexikon):
1. Schritt: übereinstimmungen in den begriffstiteln
2.: -"- beschreibungen
3.: -"- kommentaren

wenn man jetzt nach "rotor" sucht, was auch unter 1. gefunden wird, soll es nicht mehr unter 2. aufscheinen. wie mach ich das am besten?

PHP-Code:

    $query1 "SELECT * FROM begriffe WHERE MATCH(begriff) AGAINST('$suche*' IN BOOLEAN MODE);";
    
$query2 "SELECT * FROM begriffe WHERE MATCH(text) AGAINST('$suche*' IN BOOLEAN MODE);";
    
$query3 "SELECT * FROM comments WHERE MATCH(comment) AGAINST('$suche*' IN BOOLEAN MODE);"


pc.net 23.09.2004 17:08

konkretisiere "suche" ... ist das alles in einer tabelle? schaut nicht so aus ... du hast lt. deinem beispiel mindestens 2 tabellen (begriffe, comments) ...

am besten beide tabellen joinen und dann in der where-clause mit "or" die einzelnen kriterien prüfen ...

zb.:
Code:

select *
from begriffe b,
    comments c
where c.begriff_id = b.id              /* join, gemäß deiner primär und fremdschlüssel anzupassen */
  and (  b.begriff like '%[suchwort]%'
      or b.text    like '%[suchwort]%'
      or c.comment like '%[suchwort]%'
      )
;


lual 28.09.2004 17:55

hallo,
zu deinem ersten problem gibt es auch eine zweite lösung, die möglicherweise schneller ist (falls das eine rolle spielt).

select t1.artnr
from tab1 t1
EXCEPT CORRESPONDING (artnr)
select t2.artnr
from tab2 t2
;

für ORACLE schaut das selbe so aus:

select t1.artnr
from tab1 t1
MINUS
select t2.artnr
from tab2 t2
;


Alle Zeitangaben in WEZ +2. Es ist jetzt 14:28 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag