Wednesday 15 January 2014

php - INNER JOIN unique column mysql -


I have planned to use three tables for my site tagging system, they look like this:

  | ----------------------- | | ==> Photos | | - & gt; ID | | - & gt; Custom_id | | - & gt; Title | | - & gt; Slug | | - & gt; Date | | - & gt; Image_url | | ----------------------- | | ==> Tag | | - & gt; ID | | - & gt; Slug | | - & gt; Title | | ----------------------- | | ==> Tag_relation | | - & gt; TID | & Lt; - This tag is .id. - & gt; PID | & Lt; - This photo.custom_id | ----------------------- |  

So, to bring recent posts of a specific tag, I am using Inner Join with the following query:

  SELECT p. Id, p.custom_id, p.title, p.slug, p.date, p.image_url, t.id, t.slug, tr * Inner GN tags with tag * T.Ed = Tritified Inner join photo on pole on pole. Custom_id = tr.pid WHERE t.slug = 'People' ORDER BY p.date DESC LIMIT 20  

Everything works fine except for the fact that 'Slug, Id, Title' The column table of the table is being replaced by the 'Slog, Id, Title' column of the tag table!
I discovered a solution that is changing the tag column name, but is there any best method to solve this problem? Thanks

I think you should use aliases. For example:

  SELECT p.id AS Person_Id, p.title AS Person_Title ...  

You can learn more about aliases.


No comments:

Post a Comment