Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

SELECT with numbers

Codes here !

Moderators: macek, egami, gesf

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!
gurumeditation
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jul 04, 2003 6:01 am

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

What are you even trying to do?
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

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;
DigitalRice
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Jun 27, 2003 10:05 pm

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
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.