S
S
sergey4kin2021-04-27 20:23:46
SQL
sergey4kin, 2021-04-27 20:23:46

How to JOIN two SQL tables if one of the columns is text and contains extra data?

There are two tables that need to be JOIN . The problem is that in the first table the required column "id" is in int64, and in the second table it is in the form of text with a prefix ("abc123", "abc456"). Converting the "id" of the first table into text and adding a prefix to it, or trimming the column prefix of the second table and converting it to a number - does not work.

Mistake -

JOIN: each equality predicate argument must depend on exactly one JOIN input

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-04-27
@sergey4kin

SELECT a.id, b.comment
FROM a
INNER JOIN b
ON a.id = CAST(SUBSTRING(b.prefid, 4) AS UNSIGNED)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question