SELECT with numbers

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Fri Jul 04, 2003 6:01 am

SELECT with numbers

Postby gurumeditation » Fri Jul 04, 2003 6:12 am

I want to use the INSERT ... SELECT syntax to rapidly add data into a table, using some data from another table. In my SELECT statement I want to have a constant integer as first field and a field of the FROM table as second. So I tried:
INSERT INTO table1 (filed1,field2) SELECT 1,field3 FROM table2;
but I had some strange behaviour!
When trying just the SELECT statement it gives me:
SELECT 1,field3 FROM table2
1, xxx
2, yyy
3, zzz
and so on.
If I try the following, it gives me what I want:
SELECT 10,field3 FROM table3
10, xxx
10, yyy
10, zzz
Has anyone an idea why it does not behave the same way? Quotes are not helping, the only workaround was to add a '+' sign before 1!

New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby Joel » Fri Jul 04, 2003 7:09 pm

What are you even trying to do?

New php-forum User
New php-forum User
Posts: 29
Joined: Fri Jun 27, 2003 10:05 pm

Postby DigitalRice » Sat Jul 05, 2003 8:29 am

why don't you do like this:
INSERT INTO table1 (field1, field2) SELECT field4, field3 FROM table2 WHERE field4 = 1;

User avatar
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Re: SELECT with numbers

Postby WiZARD » Sun Jul 06, 2003 12:47 am

To you gurumeditation need read more about sintax of MySQL and PHP

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 3 guests