Bluehost.com Web Hosting $6.95

Special query with multiples fields

This is a discussion on Special query with multiples fields within the MySQL Database forums, part of the Database Forums category; Hello, (And sorry for my english, caus' I'm french) I've got a problem with a MySql query : SELECT * ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-15-2007
Yttrium
 
Posts: n/a
Default Special query with multiples fields

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
Reply With Quote
  #2 (permalink)  
Old 01-15-2007
Robert Klemme
 
Posts: n/a
Default Re: Special query with multiples fields

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
Reply With Quote
  #3 (permalink)  
Old 01-15-2007
Harald Fuchs
 
Posts: n/a
Default Re: Special query with multiples fields

In article <45aba0db$0$5091$ba4acef3@news.orange.fr>,
Yttrium <POUSSIERES.ngtrash@gmail.com> 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'))
Reply With Quote
  #4 (permalink)  
Old 01-15-2007
Captain Paralytic
 
Posts: n/a
Default Re: Special query with multiples fields


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')

Reply With Quote
  #5 (permalink)  
Old 01-15-2007
Willem Bogaerts
 
Posts: n/a
Default Re: Special query with multiples fields

> 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/
Reply With Quote
  #6 (permalink)  
Old 01-15-2007
Yttrium
 
Posts: n/a
Default Re: Special query with multiples fields

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
Reply With Quote
  #7 (permalink)  
Old 01-16-2007
Willem Bogaerts
 
Posts: n/a
Default Re: Special query with multiples fields

>>> 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/
Reply With Quote
  #8 (permalink)  
Old 01-16-2007
Captain Paralytic
 
Posts: n/a
Default Re: Special query with multiples fields


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!

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:22 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0