WordPress.org

Ready to get started?Download WordPress

Forums

Display data from two table by wpdb (4 posts)

  1. Harunur rashid
    Member
    Posted 7 months ago #

    i have two table tableA and tableB
    the id field is unique (PK)

    tableA
    =====
    id user_name
    1 harun
    2 mamun
    3 titu
    4 jaker
    5 litu

    tableB
    ====
    id amount
    1 5200
    3 2000

    i have made a query with $wpdb

    "SELECT tableA.id,tableA.user_name,tableB.id,tableB.amount
    WHERE tableA.id=tableB.id"

    for this query i found the result
    id user_name amount
    1 harun 5200
    3 titu 2000

    but i wanna like as( all id will show but where in tableA amount not available it'll show "no amount")
    id user_name amount
    1 harun 5200
    2 mamun no amount
    3 titu 2000
    4 jaker no amount
    5 litu no amount

    please help me anybody

  2. Christian1012
    Member
    Posted 7 months ago #

    The issue is in your WHERE clause.

    The query will only return the rows where the tableA.id matches tableB.id. Thus, in any row where tableB.id is NULL, tableA.id =/= tableB.id and that row won't return true for the query.

    The sensible fix is to autoincrement each table id column, so the ID's always match, and set default NULL for amount.

  3. Harunur rashid
    Member
    Posted 7 months ago #

    What is code exactly,please @cristian

  4. Harunur rashid
    Member
    Posted 7 months ago #

    Finally i have fixed my problem with left outer join. Thanks cristian for your response

Reply

You must log in to post.

About this Topic

Tags