title: Where are the links to each media file in a whatsapp database
body: <p>I want to organize an album with all the photos from a Whatsapp group.
  With a rooted phone I have downloaded the unencrypted whatsapp databases to my computer.</p>
  
  <p>With Sqliteman on Ubuntu I've looked around, specially in the msgstore.db and can't seem to find all of the links to the images of a particular group.</p>
  
  <p>With the table "chat_list" I saw that a specific "key_remote_jid" value corresponded to the group I wanted and in the "messages" database I could use that "key_remote_jid" to get all the messages related to that group with something like: </p>
  
  <pre><code>select * from messages where key_remote_jid="53151151515-1515131313535@g.us";
  </code></pre>
  
  <p>Furthermore I can discard text messages in order to focus on the media I want (Photos and Videos mainly) by </p>
  
  <pre><code>select * from messages where key_remote_jid="53151151515-1515131313535@g.us" and  not media_wa_type = 0;
  </code></pre>
  
  <p>And some of the images there have a filename under the column "media_name" but they are only the ones I have sent.</p>
  
  <p>There is another table called "media_refs" which contains many paths of images and video but seems to only include files which have been forwarded to more than one chat and has a key which I haven't found how to relate to the "messages" table.</p>
  
  <p>The group is rather old (dating back to 2013) and it seems likely the way whatsapp handles its database has changed through the years as there are some columns which are consistently {null} in the past and not in the most recent messages (like participant_hash) and the value key_id seems to change the format at some point.</p>
  
  <p>However the Whatsapp app has no problem in showing me the a file from any moment in the past and giving me the option to open the actual file with a "Gallery"-type software, so the information is in my phone somewhere.</p>
  
  <p>The point of all this is to basically have a backup I can work with and be able to delete the images from my phone and still have them organized in the same way they were shared in that group.</p>