php - Join table, for which the table name has to be grabbed in the same query -
this question not discuss if setup of db should be, i'm not happy how is, how , refactor not done dba @ moment.
what looking way bring together table, not in advance know table name in table want bring together against.
so:
tabel transactions trans_id autherizer 001bar payment_provider_a 001foo payment_provider_b table payment_provider_a trans_id amount 001bar 50 table payment_provider_b trans_id amount 001foo 50 the table names fictional, setup identical. there transaction table, stores transaction_id , payment_provider string name (with lot of additional data, not relevant question).
would there anyway info transaction table , in query straight join on payment_provider table, table can transaction table.
i have tagged php well, since want create phone call pdo. whole php snippets not required, if insist ;). force in right direction query self sufficient. aware lacking illustration of have tried. honest haven't tried much because can't think of something, it's first time in kind of need such query.
not overly clean, can seek this:
select * transactions t bring together ( select 'payment_provider_a' name,* payment_provider_a union select 'payment_provider_b' name,* payment_provider_b ) p on t.payment_provider = p.name , t.trans_id=p.trans_id note payment_provider_x tables must have same number , types of columns. otherwise you'll need select fields mutual (there ways around if needed).
php mysql
No comments:
Post a Comment