[wp-trac] [WordPress Trac] #42304: Database joins with like field names
WordPress Trac
noreply at wordpress.org
Mon Oct 23 01:16:44 UTC 2017
#42304: Database joins with like field names
--------------------------+------------------------------
Reporter: vinlandmedia | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 4.8.2
Severity: normal | Resolution:
Keywords: close | Focuses:
--------------------------+------------------------------
Changes (by birgire):
* keywords: => close
Comment:
Thanks for the ticket and welcome to trac.
I just did a little testing and this seems to be the case.
But this isn't specific to WordPress.
It's e.g. mentioned in a [http://php.net/manual/en/mysqli.query.php#80821
comment] by user NUNTIUS, in the PHP docs on {{{mysqli_query()}}}
When running joins in SQL you may encounter a problem if you are
trying to pull two columns with the same name. mysqli returns the last in
the query when called by name. So to get what you need you can use an
alias. [..]
The workaround mentioned there is to use an alias.
So you could e.g. use:
{{{
SELECT wp_books.name AS book_name, wp_chapters.name AS chapter_name FROM
...
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42304#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list