Jump to content

mySql 5 breaks query


bcoffin

Recommended Posts

I've used MySQL 4 for years but don't understand how to translate this query
for MySQL 5. I've done a cursory search through this forum, but don't see any
queries that look similar:

[code]
SELECT t1.*, t2.*,
CONCAT(t3.a,'|',t3.b,'|',t3.c) AS abc
FROM t1,t2
LEFT JOIN t4 ON t1.id = t4.t1_id
LEFT JOIN t3 ON t1.id = t3.t1_id AND t3.[some field] = [some value]
WHERE t2.t1_id = t1.id AND t2.t1_id = [some id]
GROUP BY t1.id
ORDER BY t1.field1, t1.field2, t1.field3
[/code]

I'm getting ERROR 1054: (42S22): Unknown column 't3.a' in 'field list'

Can someone please help?

benny
Link to comment
Share on other sites

[quote author=bcoffin link=topic=112037.msg454535#msg454535 date=1161279225]
I've used MySQL 4 for years but don't understand how to translate this query
for MySQL 5. I've done a cursory search through this forum, but don't see any
queries that look similar:

[code]
SELECT t1.*, t2.*,
CONCAT(t3.a,'|',t3.b,'|',t3.c) AS abc
FROM t1,t2
LEFT JOIN t4 ON t1.id = t4.t1_id
LEFT JOIN t3 ON t1.id = t3.t1_id AND t3.[some field] = [some value]
WHERE t2.t1_id = t1.id AND t2.t1_id = [some id]
GROUP BY t1.id
ORDER BY t1.field1, t1.field2, t1.field3
[/code]

I'm getting ERROR 1054: (42S22): Unknown column 't3.a' in 'field list'

Can someone please help?

benny
[/quote]

You shouldn't need to change the syntax of the query when using MYSQL 5.

If this is not a direct copy and paste of the query that you're using then keep in mind that if you surround t3.a with backticks(`t3.a`) then "t3.a" is seen as a column name rather than a "table.column" reference.
Link to comment
Share on other sites

After reviewing MYSQL 5 Docs I do see a comment on an error that may occur when mixing "comma joins with other join types"

[quote=mysql.com]
If you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur. Information about dealing with this problem is given later in this section.
[/quote]

The error is not the same as the one posted, but if it's not a problem now it'll probably come up later on. You can change the query to the following to avoid that.

[code]
SELECT t1.*, t2.*,
CONCAT(t3.a,'|',t3.b,'|',t3.c) AS abc
FROM t1
INNER JOIN t2 ON t2.t1_id = t1.id
LEFT JOIN t4 ON t1.id = t4.t1_id
LEFT JOIN t3 ON t1.id = t3.t1_id AND t3.[some field] = [some value]
WHERE t2.t1_id = [some id]
GROUP BY t1.id
ORDER BY t1.field1, t1.field2, t1.field3
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.