Don't use the same IV twice with CBC. The ciphertext reveals when two plaintexts start with the same 16-byte block. This makes it significantly easier to brute-force partially-known plaintexts to find them in your database, as well as to obtain partial information about records (e.g. with a plausible format, it might make it easy to find people with the same name).
In fact, you should not use CBC at all. CBC is an obsolete mode that is available in a lot of libraries and mentioned in a lot of documentation because it used to be a de facto standard. But since the 1990s our knowledge of block cipher modes has improved and we know that while CBC isn't broken, it's very tricky to use correctly. There are subtle attacks when two messages are encrypted with the same key and related, but distinct IVs. There are also subtle attacks when the IV is related to the ciphertext.
What you're looking for is called deterministic encryption. Normally, encryption is randomized or pseudo-randomized, so that if you encrypt the same message twice, an adversary can't tell that it's the same message by looking at the plaintext. Encryption modes achieve this by randomizing the IV, or at least ensuring that the same IV is not reused for the same message with the same key.
There's a trick to making deterministic encryption out of normal encryption: calculate the IV from the plaintext. If the IV only depends on the plaintext, then encrypting the same plaintext twice results in the same ciphertext.
There are modes called “synthetic IV” modes that use an IV which is partly a nonce (i.e. never reused with the same key) and partly derived from the message. If you feed a constant input as the nonce, you get deterministic encryption. Two popular choices are AES-SIV and AES-GCM-SIV.
If you're stuck with antique crypto libraries (the Javascript ecosystem is unfortunately not very good when it comes to crypto), you can still use CBC, but you need to be careful. To calculate an IV from the plaintext, use SHA-256, which is commonly available and fast. But don't just take SHA-256(plaintext): the IV needs to be stored in the database (otherwise you can't decrypt), so the IV calculation must involve a secret key. You can use the first 128-bits of SHA-256(K1 + plaintext)
, where K1 is a (at least) 128-bit secret key. Use a different key from the AES encryption key because it's bad hygiene to use the same key for the same purpose, although it doesn't actually matter in practice because SHA-256 and AES are completely unrelated.
db there's an encrypted field which also needs to do join with another encrypted field in another table.
so what can you do and not depending on the encryption modes on the this and the query column. $\endgroup$