Reputation: 3773
I have 2 tables. My tables are as below. I have as script called getTag.php. The idea being a user wants to see all portfolio items I have tagged with say, php. However, I don't just want to do:
SELECT t.portfolio_item_id, p.*
FROM tags t
INNER JOIN portfolio p ON t.portfolio_item_id = p.id
WHERE t.$skillArea = '1'
I want to also get all the columns for the tag table too and join them on. So if php =1 in the tag table, get the rest of the columns in the tag table and their values too along with corresponding portfolio item row in portfolio table
Portfolio
id
item_name
url
tags
portfolio_item_id
php
html
design
CSS
etc...
Upvotes: 1
Views: 51
Reputation: 70728
SELECT t.*, p.*
FROM tags t
INNER JOIN portfolio p ON t.portfolio_item_id = p.id
WHERE t.$skillArea = '1'
You could just do SELECT *
too but I have included t and p to demonstrate where you went wrong.
p is the alias for the portfolio table
t.* brings back all columns from the tags table
You had t.portfolio_item_id which would only bring back 1 column, where * is a wildcard
which is used return all columns in that table.
Upvotes: 2