Skip to content
Advertisement

UPDATE RECORD 2 FIRST LATTER IN MYSQL [closed]

How do you update the record in the first 2 letters as in the case below.

TABLE tblBuku

1

This is the condition

2

Some Code :

UPDATE tblBuku SET Jenis = 'Informatika' WHERE NoBuku(2) = 'IF';

Advertisement

Answer

For LAST two letters:

UPDATE tblBuku SET Jenis = 'Informatika' WHERE NoBuku LIKE '%IF'

or

UPDATE tblBuku SET Jenis = 'Informatika' WHERE RIGHT(NoBuku , 2) = 'IF'

For FIRST two letters:

UPDATE tblBuku SET Jenis = 'Informatika' WHERE NoBuku LIKE 'IF%'

or

UPDATE tblBuku SET Jenis = 'Informatika' WHERE LEFT(NoBuku , 2) = 'IF'

Explanation

  • % is a wildcard. It indicates one of more of any character.
  • RIGHT and LEFT get the substring LEFT(field_name, number of characters to extract from the left)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement