database - Updating every row in a table based on another table -


i'm doing update

update room_date rd set hotel_id = (     select hotel_id room_type rt rt.room_type_id = rd.room_type_id ) room_type_id < 40000 , hotel_id null; 

there table room_date, need hotel_id added it. above query updates id based on hotel_id found in room_type table.

this works, it's slow. takes hour execute, wandering if there better/faster way.

you need indexes on columns use in joins or where-conditions. otherwise database full-table-scan (which slow).

so, in case, need indexes on:

room_date.room_type_id

room_date.hotel_id

room_type.room_type_id


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -