how to take data from one mysql table and insert it into another :?

Asked

Viewed 1,040 times

1

I’m trying to do brush validator (serial), but I don’t know how to do it.

I have two tables: "validation" and "maturity".

In the "validation" table, you have the following fields:

id(int), data(varchar), pincode(varchar), status(int)

In the "maturity" table, you have the following fields:

id(int), data(varchar)

I wanted to take the data from the validation table (date) and update to the expiration table but will only update if the serial is right when typing ! and if the status etiver 0 !

exemplo: 
0 = ainda não ativou!
1 = ja foi ativado !

someone could help me ?

  • What you want is to build a query that updates the two tables, that’s it?

  • yes! and why am I trying to make a serial activator just because I don’t know how to do it !

  • I don’t understand ! ...

1 answer

3


Assuming that the id be it autoincrement:

INSERT INTO vencimento(data)
SELECT v.data
  FROM validacao v
 WHERE v.pincode = 'xxxxxxx'
   and v.status = 0;
  • 1

    Just like that? Gee! I was already imagining one of those querys full of subquerys and it’s even relatively simple.

  • 1

    @diegofm Nothing, practically in all banks you can insert from one table in the other only with select. Usually in the instinct we put the values to test and it doesn’t work.

  • Sarock could help me ?

  • It worked not Sorack !

  • What mistake you made?

  • gave nothing and also did not insert anything !

  • my code this way http://pastebin.com/ZucDrr2i wanted to put this in this code could help me ?

  • but you passed the pincode as parameter? o xxxxxxxx was just an example

  • I passed the brush with parameter in the bank INSERT INTO expiration(date) SELECT v.data FROM validacao v WHERE v.pincode = 'd41d8cd98f00b204e9800998ecf8427e' and v.status = 1;

  • @Roooliveira What do you want him to do for you? I think it’s kind of laudable that he’s helping you, but playing code and saying "do it for me" isn’t going to make you learn, and it’s not really the site’s focus. If it is complicated to do, it may be interesting to review what you know and what you need to learn before going to more advanced things, and go making the simplest.

  • I don’t want him to do it for me I just want a brief explanation

  • yes I understand more an explanation would be good !

  • 1

    @Roooliveira Tests right into your seat first to see if it’ll work. It’s always good to break the problem into smaller pieces to make it easier to solve

  • got it worked out more ! I’m trying to do I’m without logica ! http://pastebin.com/7kfDrfHD

  • @Roooliveira Anything opens another question with the doubt that arose

  • open another !...

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.