Jump to content


Photo

FROM WHERE


  • Please log in to reply
8 replies to this topic

#1 destined

destined
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationFlorida

Posted 09 June 2006 - 03:20 PM

Thanks for looking
Iam useing phpMyAdmin and tryin to run a query
tables: newsletter, emails

I am getteing this
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' firstname)' at line 2
I have tryed a few variations of this
I know this is a simple thing to most but not to me Please help

INSERT INTO emails (email, name)
SELECT * FROM newsletter WHERE (emailaddress, firstname)

i tryed closing it with ";
[!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--][!--fonto:Comic Sans Ms--][span style="font-family:Comic Sans Ms"][!--/fonto--]May God bless you today and always[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]
[a href="http://www.destinedtowin.org/" target="_blank"]you are Destined To Win[/a]

#2 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:23 PM

You need:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']INSERT[/span] INTO `emails` (email, name)
[span style=\'color:blue;font-weight:bold\']SELECT[/span] `emailaddress`, `firstname` FROM `newsletter`; [!--sql2--][/div][!--sql3--]That will insert the firstname and emailaddress from each row in the newsletter table into a new row in the emails table.
[table]



Don't worry, the printer fairies will sort it out.

#3 destined

destined
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationFlorida

Posted 09 June 2006 - 03:28 PM

[!--quoteo(post=381888:date=Jun 9 2006, 11:23 AM:name=Fyorl)--][div class=\'quotetop\']QUOTE(Fyorl @ Jun 9 2006, 11:23 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You need:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']INSERT[/span] INTO `emails` (email, name)
[span style=\'color:blue;font-weight:bold\']SELECT[/span] `emailaddress`, `firstname` FROM `newsletter`; [!--sql2--][/div][!--sql3--]That will insert the firstname and emailaddress from each row in the newsletter table into a new row in the emails table.
[/quote]
Thank you for the quick reply
God bless
[!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--][!--fonto:Comic Sans Ms--][span style="font-family:Comic Sans Ms"][!--/fonto--]May God bless you today and always[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]
[a href="http://www.destinedtowin.org/" target="_blank"]you are Destined To Win[/a]

#4 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 03:35 PM

you have to do it this way however:

INSERT INTO `emails` (email, name) VALUES ((SELECT `emailaddress`, `firstname` FROM `newsletter` WHERE `id` = '$id'), (SELECT `emailaddress`, `firstname` FROM `newsletter` WHERE `id` = '$id')) WHERE `id` = '$id'

assuming you want to copy accross the values. the selected rows will have to be single rows and single results within VALUES ()
z..z..z..z..z..z..z..z..

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:40 PM

[!--quoteo(post=381895:date=Jun 9 2006, 10:35 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 9 2006, 10:35 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you have to do it this way however:

INSERT INTO `emails` (email, name) VALUES ((SELECT `emailaddress`, `firstname` FROM `newsletter` WHERE `id` = '$id'), (SELECT `emailaddress`, `firstname` FROM `newsletter` WHERE `id` = '$id')) WHERE `id` = '$id'

assuming you want to copy accross the values. the selected rows will have to be single rows and single results within VALUES ()
[/quote]
Actually, that's not necessary. My method will work perfectly. SQL will insert each row returned by the SELECT statement (as long as the column names match up, which they do in my example), so it doesn't need to return single rows within VALUES(). In fact, VALUES is not needed at all.
[table]



Don't worry, the printer fairies will sort it out.

#6 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 03:48 PM

ok ok ok it's not a one line query
z..z..z..z..z..z..z..z..

#7 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:58 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]ok ok ok it's not a one line query[/quote]
Even if it was, my method would still work.
[table]



Don't worry, the printer fairies will sort it out.

#8 destined

destined
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationFlorida

Posted 09 June 2006 - 04:13 PM

ok ok ok ...lol

i used the first method before comming back here and it work for what i needed to do
But now i need to get the same emailaddress/firstname from an other database (users)
table: tbl_users

Thank You both for your help
[!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--][!--fonto:Comic Sans Ms--][span style="font-family:Comic Sans Ms"][!--/fonto--]May God bless you today and always[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]
[a href="http://www.destinedtowin.org/" target="_blank"]you are Destined To Win[/a]

#9 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 05:20 PM

I'm not so sure about this one. You'd probably have to use PHP, can't think of any way of doing it from PHPMyAdmin
[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users