insert - Inserting last record fields in the next record in mysql -


I have a table in mysql before it has some records, its fields have A, B and C. Sometimes I enter a record in this table, like with different values:

  $ query = "table (A, B, C) values ​​(INSERT '1', '0' '2') ";  

The values ​​are characters. The last record in the table is 5, 6, 4. I mean one = 5, B = 6 and C = 4 and I want to insert a new record. My values ​​are 1 and 0 and 2 but I want you to help me for this method: When B == 0, I do not want to save it and instead, I want to save the last field in the table. For example I am inserting 1, 0, 2 and it just inserts a = 1 and c = 2, but it inserts the last field from 0 instead of this table, which is 6.

Something like this:

  Insert ($ 1) in the table (A, B, C) values ​​(false) {$ query}, the last value in the table , '2')"; }  

I do not read the last record of the table and do not use its value because it can reduce the speed for me and the speed is very important. It is better to use a mysql command Does that automatically.

As you need the data that has the last data you need to get it from anywhere. The first thing that comes to mind: Read the table and look for the last recorded record that you do not want, probably because the data is too big to reach the data quickly.

You need a lookup table, which contains only the last value (i.e. one record):

  create a table last_insert_mytable (a varchar, b verarchar, c varchar );  

that you fill with a trigger:

  create triggers trg_mytable_last_insert for each row start deleting from last_insert_mytable after putting it on mytable; Insert last_insert_mytable (a, b, c) value (new.a, new.b, new.c); End;  

Then your inclusion statement looks like this:

  Insert in mytable (a, b, c) value ('1', (last_insert_mytable by b) Select)), '2');  

or (already has a record in the last_int_metable):

  Insert in mytable (A, B, C) '1', B, Last_insert_mytable From '2'; Keep in mind that due to the trigger, each entry gets a little slower, and there is only one record to deal with, so to see the last recorded record in my televetables fast It is possible. It depends on the size of the mercable. It is for putting each in the meritable if it is rarely to see at least the latest record, instead of being involved in a slow motion every now, it may be better to do a slow looking now, Just try it 


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -