• 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    Thread Starter Md Harun

    (@haruncpi)

    What is code exactly,please @cristian

    Thread Starter Md Harun

    (@haruncpi)

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display data from two table by wpdb’ is closed to new replies.