Reputation: 27
I have the two following tables
Order
ID| DETAILS | AMOUNT
-------------------------------
0 |#Battery#Client1234 | 90USD
Client
ID | NAME
--------------
1234 | JohnDoe
How can I join these two tables since the foreign key in the Order table is aggregated with some other information ?
Upvotes: 0
Views: 160
Reputation: 4939
You can extract the client id from the order details using MySQL SUBSTRING_INDEX() function and use it to do a join with the client table. Here is the query:
SELECT *
FROM `order` o
LEFT JOIN client c
ON c.id=SUBSTRING_INDEX(o.details,'#Client',-1);
Upvotes: 0
Reputation: 17289
http://sqlfiddle.com/#!9/a8c9f6/1
SELECT o.*, c.*
FROM `order` o
LEFT JOIN client c
ON o.details LIKE CONCAT('%#Client',c.id)
Upvotes: 1
Reputation: 1056
Try:
SELECT *
FROM Orders oo
JOIN Client cc
ON oo.details LIKE CONCAT('%', cc.id, '%');
Upvotes: 0
Reputation: 42
Break your column DETAILS
into two OrderDerails
and CLientID
and join ClientID with second table.
Upvotes: 3