If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL:Is any error with this query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-09, 18:33
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
MySQL:Is any error with this query

MySQL

Code:
$query1 ="INSERT INTO $CanceledCustomersTable (SELECT * FROM $CustomersTable WHERE status='deleted' AND email='$email2' AND password='$password2');";
Is any error with this query if $CanceledCustomersTable & $CustomersTable are identical of exactly BUT first field is AUTOINCREMENT in $CustomersTable something non-true in $CanceledCustomersTable ...? Always gives false(=>$result1 = @mysql_query($query1,$linkid)...

to use in a MySQL Transaction...
Reply With Quote
  #2 (permalink)  
Old 11-06-09, 19:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
Is any error with this query
yes, is any error

first, remove the parentheses around the SELECT

second, replace the dreaded, evil "select star" (SELECT * ) with a list of all the columns except the auto_increment

then add the list of all columns except the auto_increment in parentheses in front of the SELECT

INSERT INTO foo ( col2, col3, col4 )
SELECT col2, col3, col4 FROM foo WHERE ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-07-09, 05:33
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
Q1: This way autoincreament field it will be included ? I want to be included...
Please note $CanceledCustomersTable & $CustomersTable are identical of exactly BUT first field is AUTOINCREMENT in $CustomersTable something non-true in $CanceledCustomersTable ...

Q2: If I insert in a table two identical records(no autoincreament) it will give error and do not insert second correct ?
Reply With Quote
  #4 (permalink)  
Old 11-07-09, 06:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you need to start testing

create two identical tables, add some rows, and give it a try

it will be easier for you than constantly coming back here and asking
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-09-09, 06:03
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
I guess $CanceledCustomersTable can NOT have an AUTOINCREAMENT FIELD?
in an AUTOINCREAMENT FIELD of a new table, how I may start count from 10000 [10001, 10002,...]?
Reply With Quote
  #6 (permalink)  
Old 11-09-09, 06:12
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
why are you trying to achieve this?

autonumber fields have no meaning outside the system they were created in. there are good arguemnt never to show the autogenerated number to a user, precisely beaucse they then try to assign another meaning to the autonumber column.

if you need a number to have significance outside the system then explcitly create such a number from a suitable method. that may mean locking the table to grab the next value, then releaseing the locks.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old 11-09-09, 06:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
in an AUTOINCREAMENT FIELD of a new table, how I may start count from 10000 [10001, 10002,...]?
you simply gots to start testing some of this stuff yourself...
Code:
CREATE TABLE lse123
( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, foo VARCHAR(99)
) AUTO_INCREMENT = 10000
;
INSERT INTO lse123 (foo) 
VALUES ( 'nine' ) , ( 'three' ) , ( 'seven' ) 
;
SELECT * FROM lse123
;
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 11-22-09, 09:43
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
If I convert autoincreament to non autoincreament then the table will be sorted my the old field that was autoincreament ? now interger...
Reply With Quote
  #9 (permalink)  
Old 11-22-09, 09:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
If I convert autoincreament to non autoincreament then the table will be sorted my the old field that was autoincreament ? now interger...
tables are not sorted in any way

only query results are sorted

if you want to see data in a particular sequence, use SELECT with ORDER BY

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 11-24-09, 17:42
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
I think what the OP is after is to actually carry the nbr from the one table into the other. Meaning in his active table he has auto-increment on a column and in second table he has same name column, but it doesn't auto-increment. That is fine, then you just go back to Rudy's original query and add that column into the insert and select portion.
Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On