简体   繁体   中英

selecting from two tables on mysql

I am trying to insert values by selecting from two different tables last inserted values. This code should work but it gives me error in 'SELECT MAX(users.id). I am sure have spelled right. What else can be wrong?

$query1 = "INSERT INTO post(postid, userid,  readornot)
            SELECT MAX(post.postid), SELECT MAX(users.id), 
            :readornot FROM post, users  ";     
$select1 = $db->prepare($query1); ':readornot' => $readornot ));    
$query1 = "INSERT INTO post(postid, userid,  readornot)
           VALUES (
            (SELECT MAX(post.postid) FROM post) p, 
            (SELECT MAX(users.id) FROM users) u, 
            :readornot  
              )";     
$select1 = $db->prepare($query1); ':readornot' => $readornot ));

something like this, i think

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM