I need one update query

Hi i fount this issue i need single update query with limit use

student code image

i have student code 20000 recods i need update query

student code image
0000001 0000001.jpg

this type of output i need.

Not sure I understand your question, but a typical update query is in this format

UPDATE TableName
   SET Field1 = 'new Value to set'
 WHERE Field2 = 'Value to search upon'

Note the single quotes ('). Those are there to delimit strings. If you are setting or searching for a numeric value, then eliminate the quotes. Only exception to that rule is if you are looking or searching for a date, treat them like strings and surround them with quotes.

Actually i need student code value update image field

for example:

Student code value = 0000001

image = no_image.jpg

i need this type of output

student code =0000001

image = 0000001.jpg

Try writing that requirement in the update syntax Dave posted?

i need one single update query update the rows i explain previous post

UPDATE daTable
   SET image = CONCAT(RIGHT(CONCAT('000000',student_code),7),'.jpg')

That query looks good, but I have a feeling rkrajeshkannanmca will be back soon looking for LPAD

* hint, follow the link to the documentation.

In this case you should store the extension of the image, you already know the student code.

There is no need to store the name of the file, as you can combine these easily. Either in the code side, or through a view.

Assuming this is for a web application, to avoid cache issues I would strongly recommend to also store a version with the image, making the final name in the end 0000001v2.jpg etc.

1 Like

It’s ok how can i update this table send me a sql query

UPDATE student as a

JOIN existing_student as b
ON a.stu_code = b.new_student_code

SET a.images = CONCAT(‘b.new_student_code’ ,‘.jpg’)

how to set limit for this query

OK, I’ve given you an example to start from and @r937 has given you a working example. What have YOU tried that’s not working?

that’s not going to do what you think – you need to test, test, test

also, why do you want a limit?

1 Like

because i have one lakh record so only i’m asking

You can set a limit on the number of updates by using the WHERE clause.
For example, at the end of your update query use
WHERE stu_code >= 0000001 AND stu_code <= 0000100

This would update only the records with student codes from 000001 to 0000100

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.