Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvanced Search Query with multiple INNER JOIN doesn't work as expected
    primarykey
    data
    text
    <p><strong>Structure</strong></p> <hr> <p><strong>members</strong> id (auto, int), fullName (varchar), isReseller (enum), reseller_id (int), country_id, city_id, town_id, landLine, admin (enum)</p> <p><strong>subscriptions</strong> id (auto, int), transaction_id (int), magazine_id (int), cargo (varchar), startDate(date), endDate(date), active(enum), status (enum), reseller_id (int), member_id (int)</p> <p><strong>transactions</strong> id (auto, int), bankaccount_id (int), member_id (int), creator_admin_id(int), paymentDate (date)</p> <p><strong>magazines</strong> id (auto,int), name (varchar)</p> <p><strong>bankaccounts</strong> id (auto,int), name(varchar)</p> <p><strong>Query</strong></p> <hr> <pre><code>SELECT s.id, s.cargo, s.startDate, s.endDate, s.active, s.status, mag.name as magazineName, b.name as bankName, t.id as transaction_id, m.fullName, m.id as member_id, mm.fullName as resellerName, mm.id as reseller_id FROM asw_subscriptions as s INNER JOIN asw_members as m ON m.id = s.member_id INNER JOIN asw_transactions as t ON t.id = s.transaction_id INNER JOIN asw_members as mm ON mm.id = t.member_id INNER JOIN asw_magazines as mag ON mag.id = s.magazine_id INNER JOIN asw_bankaccounts as b ON b.id = t.bankaccount_id WHERE m.fullName LIKE '%john%' AND m.country_id = '224' AND m.admin = '0' AND m.reseller_id = '45677' AND s.magazine_id = '1' AND s.active = '1' AND s.reseller_id = '45677' AND t.paymentDate BETWEEN '2011-10-01' AND '2011-10-29' AND t.creator_admin_id = '45677' OR t.member_id = '45677' ORDER BY id DESC LIMIT 0, 25 </code></pre> <p><strong>PROBLEM</strong></p> <hr> <ol> <li>Resellers can place order for other members.</li> <li>I keep resellers in the same database as members. isReseller value is 1.</li> <li>When a member has reseller, reseller_id is greater than 0 (member id value of reseller).</li> <li>When reseller places an order it also creates transaction record.</li> </ol> <p>This query above displays every subscription order is done by reseller regardless to any search criteria for members and subscription status (if I search <code>active = '1'</code>, it still displays all).</p> <p>Even if I will write John, it will display all orders of selected reseller.</p> <p>It just like as if I made a query just for searching reseller's order with given payment dates (<code>t.paymentDate BETWEEN '2011-10-01' AND '2011-10-29'</code> ).</p> <p>I don't know howelse to explain this situation. If I wasn't clear please let me know, I will try edit my question and be more specific.</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload