Combining several database table together?

前端 未结 2 1575
不知归路
不知归路 2020-12-12 08:32

I have two tables tour_foreign&tour_foreign_residence in database and want merger this two table together that get output from PHP code as foll

相关标签:
2条回答
  • 2020-12-12 09:00

    Not sure why you are joining on @rownum, it might be messing with your result set. Try taking it out and see if it works.

    Your inner join looks ok, except I have never seen it with the wrapped parens, but I suspect it will work as expected. To test your query you could remove the complicated where clause and just put something like where tour_foreign.id = 1.

    Something like:

    SELECT
        tf.*
    FROM 
        tour_foreign AS tf
    INNER JOIN
        tour_foreign_residence AS tfr
    ON
        tfr.relation = tf.id
    WHERE
        tf.id = 1
    

    I implemented aliases for your longer table names (tf, and tfr) as they are easier to work with.

    0 讨论(0)
  • 2020-12-12 09:03

    Try using GROUP_CONCAT() to join the names from you tour_foreign_residence table

    0 讨论(0)
提交回复
热议问题