After a long work on it i am here going to ask my question, its simple but i don't know why it is not working, please help!!!
I have a table
phpfox_friend (where i have the below columns)
friend_id
user_id
friend_user_id
ordering
phpfox_user (where i have below columns)
usre_id
user_name
status_id
full_name
I am trying to inner join it by using below mentioned Sql query, but it give me an error
#1054 - Unknown column 'phpfox_friend.user_id' in 'on clause'
Query
SELECT *
FROM `phpfox_friend`
INNER JOIN `phpfox_user`
ON `phpfox_friend.user_id`=`phpfox_user.user_id`
WHERE phpfox_user.user_name IS NOT NULL
Kindly guide me what i am doing wrong in it
try this:
SELECT * FROM `phpfox_friend`
INNER JOIN `phpfox_user` ON
`phpfox_friend`.`user_id`=`phpfox_user`.`user_id`
WHERE `phpfox_user`.`user_name` IS NOT NULL
you need to add the quotes to tables and to the fields.
so use
`phpfox_friend`.`user_id` instead of `phpfox_friend.user_id`
Related
I am trying to get a field which is calculated by a subquery. I found about 400 posts at SO that state that you can use the outer ID in a select subquery clause unless you are trying to use it in a join (what I don't).
Here's my query:
SELECT (SELECT group_concat(ct.NAME)
FROM core_tagobject cto
JOIN core_tag ct ON ct.id=cto.tag_id
AND cto.context="tags_working_on"
AND cto.object_id=u.id) AS "tag_list"
FROM auth_user u
I always get back SQL error (1054) - unknown column 'u.id' in 'on clause'.
What am I doing wrong?
Thx!
I guess you want below sql
SELECT group_concat(ct.NAME) AS `tag_list`
FROM core_tagobject cto JOIN core_tag ct ON ct.id=cto.tag_id
JOIN auth_user u ON cto.object_id=u.id
WHERE cto.context="tags_working_on"
With some data examples would be better to produce a proper solution, but could you try:
SELECT tag_list.*
FROM auth_user u
INNER JOIN (
SELECT group_concat(ct.NAME)
FROM core_tagobject cto
JOIN core_tag ct ON ct.id=cto.tag_id
AND cto.context="tags_working_on"
) AS tag_list on tag_list.object_id=u.id ;
I'm getting an error (#1054 - Unknown column 'post.make_id' in 'on clause' ) with the following query :
SELECT `post`.*
FROM `post`,
`city` `postCity`
LEFT JOIN `make` ON `post`.`make_id` = `make`.`id`
If I remove city` `postCity, no error.
Is there any way for me to query the city table even though it's not related to the post table and at the same time do the left join with other tables ?
I think your problem is the mixing of commas with proper JOIN syntax.
Does this do what you want?
SELECT p.*
FROM post p CROSS JOIN
city c LEFT JOIN
make m
ON p.make_id = m.id;
I'm not sure what you are trying to accomplish. This doesn't look particularly useful, but it might fix your syntax error.
Can you assist me with my query? I keep receiving an error that states "Error Code: 1054. Unknown column 'cdata.customerid' in 'on clause'"
If I want to attach the left join data where the customer id's match from customerdata table and order table, how can I achieve this? I must not understand at what point SQL allows data to become accessible by different parts of the query.
select
cdata.customerid,
cdata.affiliate,
cdata.firstname,
cdata.address1,
cdata.address2,
cdata.city,
cdata.state,
cdata.postalcode,
cdata.emailaddress,
cdata.active
from customerdata cdata, order a
left join
(select
a.transactiondate,
sum(a.TransactionAmount),
a.id
from order a
group by a.id)
txns on a.id = cdata.customerid
where cdata.active = "A";
In on clause you have to specify fields that belong to the tables which are taking part in join clause. So, if you are joining cdata with the txns subquery, you have to probably join on txns.id and cdata.customerid. You probably also wanted to get your sum out of your subquery, so you have to include this field in your main SELECT clause. And you probably have to specify transactiondate field in your group by clause, at least this is necessary for ORACLE DB, I am not sure if this is the case for MySQL:
select
cdata.customerid,
cdata.affiliate,
cdata.firstname,
cdata.address1,
cdata.address2,
cdata.city,
cdata.state,
cdata.postalcode,
cdata.emailaddress,
cdata.active,
txns.tsum,
txns.transactiondate
from customerdata cdata
left join
(select
a.transactiondate,
sum(a.TransactionAmount) tsum,
a.id
from order a
group by a.id, a.transactiondate) txns
on txns.id = cdata.customerid
where cdata.active = "A";
The JOIN references the table 'order' and the table 'txns', 'cdata' is not involved here, so within the context of the join cdata.customerid does not exist.
This is my mysql query
SELECT tm.MAGAZINE_ID, tm.MAGAZINE_NAME,tm.MAGAZINE_DESCRIPTION,pub.publisher_name,
tmi.COVER_PAGE_THUMB AS COVER_PAGE_VERTICAL,tmi.FROM_DATE AS ISSUE_DATE,
tm.html_flag AS HTML_EXIST,tm.CATEGORY_ID,tm.language_id,tm.is_free,tma.AppUrl,
(SELECT issue_id from tbl_magazine_issue WHERE magazine_id = 141
ORDER BY FROM_DATE DESC LIMIT 1) as temp_issue_id
FROM tbl_magazine_apps as tma
LEFT OUTER JOIN tbl_magazine_code as tmc ON tmc.Code = tma.AppsCode
LEFT OUTER JOIN `tbl_magazine` AS tm ON tmc.magazine_Id = tm.MAGAZINE_ID
JOIN `tbl_magazine_issue` AS tmi ON temp_issue_id = tmi.issue_id
LEFT OUTER JOIN mst_publisher AS pub ON tm.publisher_id=pub.publisher_id
WHERE
tmi.PUBLISH_STATUS IN(1,3)
AND tmi.`OS_SELECT` = '".$osType."'
AND tma.id IN (".$appIds.")
GROUP BY tm.MAGAZINE_ID
ORDER BY tmi.ISSUE_DATE DESC
but i got an error that
#1054 - Unknown column 'temp_issue_id' in 'on clause'
if any one know about this please help me. i am new to this
AFAIK The subquery belongs to the from part:
http://dev.mysql.com/doc/refman/5.7/en/from-clause-subqueries.html
So I would join the subquery.
Like:
SELECT a.a, b.b
FROM table1 as a
JOIN (SELECT b from table2) as b ON a.key = b.key;
As the message suggests, the column temp_issue_id is not in any of the following tables: tbl_magazine_apps, tbl_magazine, or tbl_magazine_issue. It is also not a variable in the environment.
Beyond that, it is pretty much impossible for anyone to figure out how to fix the problem without more knowledge about the data structure.
If I were to hazard a guess, based on the table names, that particular join would be:
JOIN `tbl_magazine_issue` AS tmi ON tm.magazine_id = tmi.magazine_id
because it makes sense to me that a magazine issue would be connect to a magazine. I have no idea what temp_issue_id is, though.
temp_issue_id give alias name for specifying this column i think it should be tm.issue_id
temp_issue_id is column's name as per the query. You need it to convert to table and use subsequent column in your SELECT clause.
Guys was looking for a little help. I was trying to run this query in php myadmin. Needing to update a temp table with 4 sets of data..3 sets from one table..and 1 from another table, while joining 3 tables. The error comes back after my second JOIN that I do not have a unique table alias. I'm not sure how to fix that. Can anyone see where the query is going wrong? Thanks.
INSERT INTO jos_jxgallery_assign_ratings_temp( image_id, pscore, hits, contest_id )
SELECT jos_jxgallery_images.image_id, jos_jxgallery_images.pscore, jos_jxgallery_images.hits, jos_jxgallery_contests.contest_id
FROM jos_jxgallery_images, jos_jxgallery_contests
INNER JOIN jos_jxgallery_contest_image_map ON jos_jxgallery_images.image_id = jos_jxgallery_contest_image_map.image_id
INNER JOIN jos_jxgallery_contests ON jos_jxgallery_contest_image_map.contest_id = jos_jxgallery_contests.contest_id
WHERE jos_jxgallery_contests.published =1
AND jos_jxgallery_images.published =1
ORDER BY jos_jxgallery_images.pscore DESC , jos_jxgallery_images.hits DESC
LIMIT 25
MySQL said: Documentation
#1066 - Not unique table/alias: 'jos_jxgallery_contests'
Now when I change the query to this...I get another error listed below the query. Any ideas?
INSERT INTO jos_jxgallery_assign_ratings_temp( image_id, pscore, hits, contest_id )
SELECT jos_jxgallery_images.image_id, jos_jxgallery_images.pscore, jos_jxgallery_images.hits, jos_jxgallery_contests.contest_id
FROM jos_jxgallery_images, jos_jxgallery_contests
INNER JOIN jos_jxgallery_contest_image_map ON jos_jxgallery_images.image_id = jos_jxgallery_contest_image_map.image_id
INNER JOIN jos_jxgallery_contests AS con ON jos_jxgallery_contest_image_map.contest_id = con.contest_id
WHERE con.published =1
AND jos_jxgallery_images.published =1
ORDER BY jos_jxgallery_images.pscore DESC , jos_jxgallery_images.hits DESC
LIMIT 25
MySQL said: Documentation
#1054 - Unknown column 'jos_jxgallery_images.image_id' in 'on clause'
You use the jos_jxgallery_contests in FROM and INNER JOIN. In INNER JOIN you make a ambiguous connection. Why you try to do that?