Answer the question
In order to leave comments, you need to log in
How to iterate in WHERE clause using data from second table?
Good day!
The task is probably not standard ... I would like to know how best to solve it so as not to change the structure of the database and whether it is worth using it that way.
In short: there are 2 tables payment_methods & user_meta.
payment_methods
+-----+-----------------+
| ID | Payment System |
+-----+-----------------+
| 563 | webmoney |
| 564 | yandex money |
| 565 | paypal |
+-----+-----------------+
+-----+----------------+---------+---------+
| ID | payment system | wallet | USER_ID |
+-----+----------------+---------+---------+
| 739 | webmoney | 14njn | 736 |
| 740 | paypal | dnjanja | 736 |
+-----+----------------+---------+---------+
SELECT * FROM `USER_META` WHERE `META_KEY` = 'webmoney' AND USER_ID = 736;
WHERE `META_KEY` = 'webmoney'
iterate from the 1st table based on the payment_methods column instead? And how correct is this implementation? Answer the question
In order to leave comments, you need to log in
Of course it's done wrong. In the user_meta table, the payment system field must point to payment_methods.id.
And so about
SELECT * FROM `USER_META` WHERE USER_ID = 736 AND `META_KEY` IN (SELECT 'PAYMENT_SYSTEM' FROM 'PAYMENTS_METHODS')
This one seems to work as well:
SELECT * FROM `USER_META` t1
INNER JOIN `PAYMENT_METHODS` t2 ON t1.META_KEY = t2.PAYMENT_SYSTEM
WHERE USER_ID = 736;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question