X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2B60632A3A7 for ; Sat, 16 Oct 2004 10:09:21 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17975-01 for ; Sat, 16 Oct 2004 09:09:16 +0000 (GMT) Received: from mail.kuehlbox.de (ns1.kuehlbox.de [62.159.47.20]) by svr1.postgresql.org (Postfix) with ESMTP id 1BB0532A3A2 for ; Sat, 16 Oct 2004 10:09:17 +0100 (BST) Received: (qmail 30343 invoked by uid 89); 16 Oct 2004 09:07:59 -0000 Received: from unknown (HELO ?172.16.21.120?) (webmaster@kuehlbox.de@82.135.7.44) by www.kuehlbox.de with SMTP; 16 Oct 2004 09:07:58 -0000 Message-ID: <4170E524.2040101@kuehlbox.de> Date: Sat, 16 Oct 2004 11:08:52 +0200 From: Stephan Fiebrandt User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: need query advice Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/129 X-Sequence-Number: 19232 Hello all, i've got a psql database, with a table including 6 rows named "zahl1 zahl2 zahl3 zahl4 zahl5 and zahl6" type integer There are about 10.000 entries in the table. In every entry, the numbers are uniq to each other. That means, if zahl1=1, then zahl2-6 cannot be also 1. Example: 1, 10, 78, 43, 2, 67 (all 6 numbers are different in the same line, never a dup) 56, 34, 78, 1, 77, 99 (but repeating in the db tousand times of course) 1, 2, 3, 4, 5, 6 2, 3, 4, 99, 5, 6 ... $a ... $f are the variables, of the 6 numbers i am searching: The numbers that are given to search, are also uniq of course, or it would not make sense. I need all hits, where at leased 5 of the given 6 numbers are maching in every entry: select * from zaehlerzuordnung_snapshots where ((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e)) or ((zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f or zahl5=$f or zahl6=$f)) or ((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f or zahl5=$f or zahl6=$f)) or ((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f or zahl5=$f or zahl6=$f)) or ((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f or zahl5=$f or zahl6=$f)) or ((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f or zahl5=$f or zahl6=$f)) ; well.. this query is working. But for sure totaly ineffictive written. I need the advice of your professionals to more simply that query. As next problem i have to search if already 4 of the given 6 numbers are machting the 6 numbers per entrie. But to write a query like i did above.. wount do the trick i guess. Any hints? i really need it soon :( greets, Yze