Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Special query with multiples fields
Old
  (#1)
Yttrium
Guest
 
Posts: n/a
Default Special query with multiples fields - 06-04-2007, 07:47 AM

Hello, (And sorry for my english, caus' I'm french)

I've got a problem with a MySql query :

SELECT *
FROM table1 as t1
WHERE (t1.field1,t1.field2,t1.field3)
IN ('a','b','c'), ('d','e','f'), ('g','h','i')

This query isn't ok, but I don't know hox to deal with this..
I want to get every lines where field1 AND field2 AND field3 is in one
of the triplet I've got...

ie:
If the line (a,b,c) is in my table, I want to get it, but if the line is
only (a,b,d), I Don't want to get it..

Perharps someone should help me to do this ?

Thanks, Regards.

And sorry again for my very bad english...

Yttrium
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Special query with multiples fields
Old
  (#2)
Robert Klemme
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM

On 15.01.2007 16:42, Yttrium wrote:
> I've got a problem with a MySql query :
>
> SELECT *
> FROM table1 as t1
> WHERE (t1.field1,t1.field2,t1.field3)
> IN ('a','b','c'), ('d','e','f'), ('g','h','i')
>
> This query isn't ok, but I don't know hox to deal with this..
> I want to get every lines where field1 AND field2 AND field3 is in one
> of the triplet I've got...
>
> ie:
> If the line (a,b,c) is in my table, I want to get it, but if the line is
> only (a,b,d), I Don't want to get it..
>
> Perharps someone should help me to do this ?


You have to explicitely formulate your condition

....
where ( t1.field1 = 'a' and t1.field2 = 'b' and ... )
or ( t1.field1 = ... and ... )

There is no other efficient way AFAIK.

Greetings from old Europe to old Europe ;-)

robert
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#3)
Harald Fuchs
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM

In article <45aba0db$0$5091$EMAIL REMOVED>,
Yttrium <EMAIL REMOVED> writes:

> Hello, (And sorry for my english, caus' I'm french)
> I've got a problem with a MySql query :


> SELECT *
> FROM table1 as t1
> WHERE (t1.field1,t1.field2,t1.field3)
> IN ('a','b','c'), ('d','e','f'), ('g','h','i')


The last line is wrong. Make that
IN (('a','b','c'), ('d','e','f'), ('g','h','i'))
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#4)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM


Yttrium wrote:

> Hello, (And sorry for my english, caus' I'm french)
>
> I've got a problem with a MySql query :
>
> SELECT *
> FROM table1 as t1
> WHERE (t1.field1,t1.field2,t1.field3)
> IN ('a','b','c'), ('d','e','f'), ('g','h','i')
>
> This query isn't ok, but I don't know hox to deal with this..
> I want to get every lines where field1 AND field2 AND field3 is in one
> of the triplet I've got...
>
> ie:
> If the line (a,b,c) is in my table, I want to get it, but if the line is
> only (a,b,d), I Don't want to get it..
>
> Perharps someone should help me to do this ?
>
> Thanks, Regards.
>
> And sorry again for my very bad english...
>
> Yttrium


What precisely you do here depends on what the real data looks like,
you may wish to substitute CONCAT_WS for CONCAT and use a separater
between the individual data items in the query below:

SELECT *
FROM table1 as t1
WHERE CONCAT(t1.field1,t1.field2,t1.field3)
IN ('abc', 'def', 'ghi')

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#5)
Willem Bogaerts
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM

> SELECT *
> FROM table1 as t1
> WHERE (t1.field1,t1.field2,t1.field3)
> IN ('a','b','c'), ('d','e','f'), ('g','h','i')


I don't think this syntax can be used with SELECT, but the HANDLER
statement can do it.

--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#6)
Yttrium
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM

Le 15/01/2007 17:10, Willem Bogaerts nous disait:
>> SELECT *
>> FROM table1 as t1
>> WHERE (t1.field1,t1.field2,t1.field3)
>> IN ('a','b','c'), ('d','e','f'), ('g','h','i')

>
> I don't think this syntax can be used with SELECT, but the HANDLER
> statement can do it.
>


What does it means exactly ?

--
[- Yttrium -]
Jetez un oeil Ã* http://www.danstesyeux.com
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#7)
Willem Bogaerts
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:47 AM

>>> SELECT *
>>> FROM table1 as t1
>>> WHERE (t1.field1,t1.field2,t1.field3)
>>> IN ('a','b','c'), ('d','e','f'), ('g','h','i')

>>
>> I don't think this syntax can be used with SELECT, but the HANDLER
>> statement can do it.
>>

>
> What does it means exactly ?
>


http://dev.mysql.com/doc/refman/4.1/en/handler.html

Seems you can't do it in one go though. Best bet is the SELECT with
conditions.

Best regards

--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Special query with multiples fields
Old
  (#8)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: Special query with multiples fields - 06-04-2007, 07:48 AM


Willem Bogaerts wrote:
> Seems you can't do it in one go though. Best bet is the SELECT with
> conditions.


My suggested query does it in one go!

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top