PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Subquery returns more than 1 row
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Subquery returns more than 1 row

Réponse
 
LinkBack Outils de la discussion
Vieux 22/10/2007, 16h33   #1
UKuser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Subquery returns more than 1 row

Hi,

What am I doing wrong with this statement?

UPDATE company
SET new_test =
concat_ws(
(
Select Property from `properties` where `Company_ ID`=1
)
,'#')
WHERE
company.`Company_ ID`=1

I want it to insert Property into the field new_test separated by a #
but it errors on me.

Any would be great.

Thanks

A

  Réponse avec citation
Vieux 22/10/2007, 16h55   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:
> Hi,
>
> What am I doing wrong with this statement?
>
> UPDATE company
> SET new_test =
> concat_ws(
> (
> Select Property from `properties` where `Company_ ID`=1
> )
> ,'#')
> WHERE
> company.`Company_ ID`=1
>
> I want it to insert Property into the field new_test separated by a #
> but it errors on me.
>
> Any would be great.
>
> Thanks
>
> A


"it errors on me"
Wow, how bl**dy useful. If my crystal ball was working I could of
course see what error you were getting. But it isn't.

So, would you care to tell us!

  Réponse avec citation
Vieux 22/10/2007, 16h56   #3
UKuser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 15:55, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:
>
>
>
> > Hi,

>
> > What am I doing wrong with this statement?

>
> > UPDATE company
> > SET new_test =
> > concat_ws(
> > (
> > Select Property from `properties` where `Company_ ID`=1
> > )
> > ,'#')
> > WHERE
> > company.`Company_ ID`=1

>
> > I want it to insert Property into the field new_test separated by a #
> > but it errors on me.

>
> > Any would be great.

>
> > Thanks

>
> > A

>
> "it errors on me"
> Wow, how bl**dy useful. If my crystal ball was working I could of
> course see what error you were getting. But it isn't.
>
> So, would you care to tell us!


"Subquery returns more than 1 row" is the error )


  Réponse avec citation
Vieux 22/10/2007, 17h03   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:
> Hi,
>
> What am I doing wrong with this statement?
>
> UPDATE company
> SET new_test =
> concat_ws(
> (
> Select Property from `properties` where `Company_ ID`=1
> )
> ,'#')
> WHERE
> company.`Company_ ID`=1
>
> I want it to insert Property into the field new_test separated by a #
> but it errors on me.
>
> Any would be great.
>
> Thanks
>
> A


Well, for a start, why are you using CONCAT_WS rather than CONCAT?
Next, are you sure that `Company_ ID` is really the column name
(spaces in column names are not a good idea)?
Next, why shouldn't the subquery return more than one row?

  Réponse avec citation
Vieux 22/10/2007, 17h08   #5
UKuser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 16:03, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:
>
>
>
> > Hi,

>
> > What am I doing wrong with this statement?

>
> > UPDATE company
> > SET new_test =
> > concat_ws(
> > (
> > Select Property from `properties` where `Company_ ID`=1
> > )
> > ,'#')
> > WHERE
> > company.`Company_ ID`=1

>
> > I want it to insert Property into the field new_test separated by a #
> > but it errors on me.

>
> > Any would be great.

>
> > Thanks

>
> > A

>
> Well, for a start, why are you using CONCAT_WS rather than CONCAT?
> Next, are you sure that `Company_ ID` is really the column name
> (spaces in column names are not a good idea)?
> Next, why shouldn't the subquery return more than one row?


I want it to return every corresponding row and insert it into my new
field. And unfortunately yes Company_ ID is the correct name.
As it stands it only inserts 1 of the fields into my new field rather
than however many are returned by the SELECT statement.

  Réponse avec citation
Vieux 22/10/2007, 17h37   #6
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 16:08, UKuser <spiderc...@yahoo.co.uk> wrote:
"As it stands it only inserts 1 of the fields into my new field rather
than however many are returned by the SELECT statement."

Your select statement only contains 1 field.

  Réponse avec citation
Vieux 22/10/2007, 17h40   #7
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 16:08, UKuser <spiderc...@yahoo.co.uk> wrote:
> On 22 Oct, 16:03, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:

>
> > > Hi,

>
> > > What am I doing wrong with this statement?

>
> > > UPDATE company
> > > SET new_test =
> > > concat_ws(
> > > (
> > > Select Property from `properties` where `Company_ ID`=1
> > > )
> > > ,'#')
> > > WHERE
> > > company.`Company_ ID`=1

>
> > > I want it to insert Property into the field new_test separated by a #
> > > but it errors on me.

>
> > > Any would be great.

>
> > > Thanks

>
> > > A

>
> > Well, for a start, why are you using CONCAT_WS rather than CONCAT?
> > Next, are you sure that `Company_ ID` is really the column name
> > (spaces in column names are not a good idea)?
> > Next, why shouldn't the subquery return more than one row?

>
> I want it to return every corresponding row and insert it into my new
> field. And unfortunately yes Company_ ID is the correct name.
> As it stands it only inserts 1 of the fields into my new field rather
> than however many are returned by the SELECT statement.- Hide quoted text -
>
> - Show quoted text -


I have a feeling that you are looking for GROUP_CONCAT()

  Réponse avec citation
Vieux 22/10/2007, 18h00   #8
UKuser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Subquery returns more than 1 row

On 22 Oct, 16:40, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 22 Oct, 16:08, UKuser <spiderc...@yahoo.co.uk> wrote:
>
>
>
> > On 22 Oct, 16:03, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > On 22 Oct, 15:33, UKuser <spiderc...@yahoo.co.uk> wrote:

>
> > > > Hi,

>
> > > > What am I doing wrong with this statement?

>
> > > > UPDATE company
> > > > SET new_test =
> > > > concat_ws(
> > > > (
> > > > Select Property from `properties` where `Company_ ID`=1
> > > > )
> > > > ,'#')
> > > > WHERE
> > > > company.`Company_ ID`=1

>
> > > > I want it to insert Property into the field new_test separated by a #
> > > > but it errors on me.

>
> > > > Any would be great.

>
> > > > Thanks

>
> > > > A

>
> > > Well, for a start, why are you using CONCAT_WS rather than CONCAT?
> > > Next, are you sure that `Company_ ID` is really the column name
> > > (spaces in column names are not a good idea)?
> > > Next, why shouldn't the subquery return more than one row?

>
> > I want it to return every corresponding row and insert it into my new
> > field. And unfortunately yes Company_ ID is the correct name.
> > As it stands it only inserts 1 of the fields into my new field rather
> > than however many are returned by the SELECT statement.- Hide quoted text -

>
> > - Show quoted text -

>
> I have a feeling that you are looking for GROUP_CONCAT()


Many thanks for that

UPDATE company
SET new_test =
(
Select GROUP_CONCAT(Property)
from `properties`
where properties.`Company_ ID`=company.`Company_ ID`
)

Has fixed it

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15776 seconds with 16 queries