SELECT WHERE IN help
am 21.09.2010 17:33:21 von Tompkins Neil
--00c09f9db0c5c285cf0490c6bfac
Content-Type: text/plain; charset=ISO-8859-1
Hi
With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can I
return two records for the record_id 3 ? Is it possible ?
Cheers
Neil
--00c09f9db0c5c285cf0490c6bfac--
Re: SELECT WHERE IN help
am 21.09.2010 17:40:48 von Johan De Meersman
--000e0cd1460c61e9e90490c6daeb
Content-Type: text/plain; charset=ISO-8859-1
If there are two, you will return two.
On Tue, Sep 21, 2010 at 5:33 PM, Tompkins Neil
> wrote:
> Hi
>
> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can I
> return two records for the record_id 3 ? Is it possible ?
>
> Cheers
> Neil
>
--
Bier met grenadyn
Is als mosterd by den wyn
Sy die't drinkt, is eene kwezel
Hy die't drinkt, is ras een ezel
--000e0cd1460c61e9e90490c6daeb--
Re: SELECT WHERE IN help
am 21.09.2010 17:44:04 von Tompkins Neil
--0015175cdfb611668f0490c6e645
Content-Type: text/plain; charset=ISO-8859-1
Thanks for the quick reply. Basically in (3,4,5,6,7,3) the record_id of 3
only exists once in the table my_table. However, because 3 exists twice
within (3,4,5,6,7,3), I want it to return two records for record_id 3. Is
it possible ?
Cheers
Neil
On Tue, Sep 21, 2010 at 4:40 PM, Johan De Meersman wrote:
> If there are two, you will return two.
>
>
> On Tue, Sep 21, 2010 at 5:33 PM, Tompkins Neil <
> neil.tompkins@googlemail.com> wrote:
>
>> Hi
>>
>> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can I
>> return two records for the record_id 3 ? Is it possible ?
>>
>> Cheers
>> Neil
>>
>
>
>
> --
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel
>
--0015175cdfb611668f0490c6e645--
Re: SELECT WHERE IN help
am 21.09.2010 17:46:16 von Johan De Meersman
--00151750dabee7e17b0490c6edde
Content-Type: text/plain; charset=ISO-8859-1
I don't think that'll work, no. Why would you want to return duplicate data
? The whole point of an RDBMS is to *avoid* duplicate data :-)
On Tue, Sep 21, 2010 at 5:44 PM, Tompkins Neil
> wrote:
> Thanks for the quick reply. Basically in (3,4,5,6,7,3) the record_id of 3
> only exists once in the table my_table. However, because 3 exists twice
> within (3,4,5,6,7,3), I want it to return two records for record_id 3.
> Is it possible ?
>
> Cheers
> Neil
>
>
> On Tue, Sep 21, 2010 at 4:40 PM, Johan De Meersman wrote:
>
>> If there are two, you will return two.
>>
>>
>> On Tue, Sep 21, 2010 at 5:33 PM, Tompkins Neil <
>> neil.tompkins@googlemail.com> wrote:
>>
>>> Hi
>>>
>>> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can I
>>> return two records for the record_id 3 ? Is it possible ?
>>>
>>> Cheers
>>> Neil
>>>
>>
>>
>>
>> --
>> Bier met grenadyn
>> Is als mosterd by den wyn
>> Sy die't drinkt, is eene kwezel
>> Hy die't drinkt, is ras een ezel
>>
>
>
--
Bier met grenadyn
Is als mosterd by den wyn
Sy die't drinkt, is eene kwezel
Hy die't drinkt, is ras een ezel
--00151750dabee7e17b0490c6edde--
Re: SELECT WHERE IN help
am 21.09.2010 17:47:40 von Tompkins Neil
--00c09f93d5dbee368e0490c6f214
Content-Type: text/plain; charset=ISO-8859-1
Thanks for the reply. The search of (3,4,5,6,7,3) is pulling data from a
table. I think in this case I need to change my design .
On Tue, Sep 21, 2010 at 4:46 PM, Johan De Meersman wrote:
> I don't think that'll work, no. Why would you want to return duplicate data
> ? The whole point of an RDBMS is to *avoid* duplicate data :-)
>
>
> On Tue, Sep 21, 2010 at 5:44 PM, Tompkins Neil <
> neil.tompkins@googlemail.com> wrote:
>
>> Thanks for the quick reply. Basically in (3,4,5,6,7,3) the record_id of
>> 3 only exists once in the table my_table. However, because 3 exists
>> twice within (3,4,5,6,7,3), I want it to return two records for
>> record_id 3. Is it possible ?
>>
>> Cheers
>> Neil
>>
>>
>> On Tue, Sep 21, 2010 at 4:40 PM, Johan De Meersman wrote:
>>
>>> If there are two, you will return two.
>>>
>>>
>>> On Tue, Sep 21, 2010 at 5:33 PM, Tompkins Neil <
>>> neil.tompkins@googlemail.com> wrote:
>>>
>>>> Hi
>>>>
>>>> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can
>>>> I
>>>> return two records for the record_id 3 ? Is it possible ?
>>>>
>>>> Cheers
>>>> Neil
>>>>
>>>
>>>
>>>
>>> --
>>> Bier met grenadyn
>>> Is als mosterd by den wyn
>>> Sy die't drinkt, is eene kwezel
>>> Hy die't drinkt, is ras een ezel
>>>
>>
>>
>
>
> --
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel
>
--00c09f93d5dbee368e0490c6f214--
Re: SELECT WHERE IN help
am 21.09.2010 17:49:30 von Mark Goodge
On 21/09/2010 16:44, Tompkins Neil wrote:
> Thanks for the quick reply. Basically in (3,4,5,6,7,3) the record_id of 3
> only exists once in the table my_table. However, because 3 exists twice
> within (3,4,5,6,7,3), I want it to return two records for record_id 3. Is
> it possible ?
No, that isn't possible.
Why do you want a duplicate record to be retrieved? There may be a
better way of doing it.
Mark
--
http://mark.goodge.co.uk
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: SELECT WHERE IN help
am 21.09.2010 19:34:48 von Joerg Bruehe
Hi Neil, all!
Tompkins Neil wrote:
> Hi
>=20
> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can=
I
> return two records for the record_id 3 ? Is it possible ?
This is a case where you may safely use natural language and logic. The
command is
SELECT all fields FROM the records in "mytable" FOR WHICH THE
FOLLOWING CONDITION IS TRUE:
the field "record_id" has a value which is IN the list 3, 4, 5, 6,
7, 3
The condition can only evaluate to "true" or "false" (ignoring NULL
values and the "unknown" truth value for now), and for that evaluation
it does not matter whether a matching value appears in your list only
once or repeatedly.
To achieve your desired effect, you might use a generator to create a
UNION statement. Roughly, the approach would be ("+=3D" means appending t=
o
a string):
value =3D first value of the list;
statement =3D "SELECT * FROM my_table WHERE record_id =3D $value";
while (there are more values in the list)
do
value =3D next value of the list;
statement +=3D
"UNION SELECT * FROM my_table WHERE record_id =3D $value";
done;
statement +=3D ";";
execute statement;
Obviously, this will create a huge statement if the value list is long,
and it doesn't seem to be efficient, so I don't recommend this technique
in general.
Before going that route, you should question your assumptions: Why is it
necessary to return the same record twice?
Jörg
--=20
Joerg Bruehe, MySQL Build Team, joerg.bruehe@oracle.com
ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin
Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven
Amtsgericht Muenchen: HRA 95603
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
RE: SELECT WHERE IN help
am 21.09.2010 19:37:05 von Jerry Schwartz
>-----Original Message-----
>From: Tompkins Neil [mailto:neil.tompkins@googlemail.com]
>Sent: Tuesday, September 21, 2010 11:48 AM
>To: Johan De Meersman
>Cc: [MySQL]
>Subject: Re: SELECT WHERE IN help
>
>Thanks for the reply. The search of (3,4,5,6,7,3) is pulling data from a
>table. I think in this case I need to change my design .
>
[JS] You can accomplish your goal by using a sub-select to create a "table"
that has 3 in it twice, and then JOIN it to the original table.
As for why you would want to do this, that's another story. It sounds like you
went down the wrong road.
Regards,
Jerry Schwartz
Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032
860.674.8796 / FAX: 860.674.8341
E-mail: jerry@gii.co.jp
Web site: www.the-infoshop.com
>On Tue, Sep 21, 2010 at 4:46 PM, Johan De Meersman wrote:
>
>> I don't think that'll work, no. Why would you want to return duplicate data
>> ? The whole point of an RDBMS is to *avoid* duplicate data :-)
>>
>>
>> On Tue, Sep 21, 2010 at 5:44 PM, Tompkins Neil <
>> neil.tompkins@googlemail.com> wrote:
>>
>>> Thanks for the quick reply. Basically in (3,4,5,6,7,3) the record_id of
>>> 3 only exists once in the table my_table. However, because 3 exists
>>> twice within (3,4,5,6,7,3), I want it to return two records for
>>> record_id 3. Is it possible ?
>>>
>>> Cheers
>>> Neil
>>>
>>>
>>> On Tue, Sep 21, 2010 at 4:40 PM, Johan De Meersman
>wrote:
>>>
>>>> If there are two, you will return two.
>>>>
>>>>
>>>> On Tue, Sep 21, 2010 at 5:33 PM, Tompkins Neil <
>>>> neil.tompkins@googlemail.com> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> With a SELECT * FROM my_table WHERE record_id IN (3,4,5,6,7,3), how can
>>>>> I
>>>>> return two records for the record_id 3 ? Is it possible ?
>>>>>
>>>>> Cheers
>>>>> Neil
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Bier met grenadyn
>>>> Is als mosterd by den wyn
>>>> Sy die't drinkt, is eene kwezel
>>>> Hy die't drinkt, is ras een ezel
>>>>
>>>
>>>
>>
>>
>> --
>> Bier met grenadyn
>> Is als mosterd by den wyn
>> Sy die't drinkt, is eene kwezel
>> Hy die't drinkt, is ras een ezel
>>
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org