September 14th, 2012, 01:21 AM
-
My first error:#1066 - Not unique table/alias: 'dammreg'
Hello,
I have to select (not a real join) the posts from the table `Dammreg` under condition that the string in the DNAM field includes the string from the field Damm_vk.NAMN (or if possible a given lenght substring).
I have used the following sentence:
SELECT * FROM Dammreg INNER JOIN Dammreg ON Dammreg.DNAMN LIKE CONCAT('%', Damm_vk.NAMN, '%');
and received the error message: #1066 - Not unique table/alias: 'Dammreg'.
I used also the sentence:
SELECT * FROM Dammreg
JOIN TABLE Dammreg ON Dammreg.DNAMN LIKE '%'+ Damm_vk.NAMN +'%' with no result.
With this sentence:
SELECT * FROM Dammreg
JOIN TABLE Dammreg ON Dammreg.DNAMN LIKE '%' + @Damm_vk.NAMN + '%'
I receive the message: #1046 - No database selected.
Erlier I read the thread about error:#1066 and some other threads but still can not find what is wrong.
Server version: 5.1.63-0+squeeze1
Many thanks in advance
Last edited by JacekVR; September 14th, 2012 at 02:29 AM.
Reason: clarification
September 14th, 2012, 07:01 AM
-
Originally Posted by JacekVR
I have to select (not a real join) ...
can you please explain a bit more what this means?
FROM Dammreg INNER JOIN Dammreg ON ...
the problem is you are doing a self-join of the table to itself, without assigning table alias names to the two different copies of the table
shouldn't you be joining Dammreg to Damm_vk instead?
September 14th, 2012, 07:03 AM
-
you will get an error because you are joining a table to itself. you can't do that unless you give one instance a different name.
Code:
SELECT
foo,
bar,
qux
FROM
yourtablename
INNER JOIN
yourtablename AS someothername
ON
yourtablename.column = someothername.column
September 14th, 2012, 01:04 PM
-
Originally Posted by r937
can you please explain a bit more what this means?
FROM Dammreg INNER JOIN Dammreg ON ...
shouldn't you be joining Dammreg to Damm_vk instead?
Yes it was the reason. Thank you.
I am a bit ahead but now the error is:
#1142 - SELECT command denied to user 'XXXXXX' for table 'Namn' although the sentence is:
SELECT * FROM Dammreg INNER JOIN Damm_vk.Namn ON Dammreg.DNAMN LIKE CONCAT('%', Damm_vk.Namn, '%');
September 14th, 2012, 01:39 PM
-
FROM Dammreg INNER JOIN Damm_vk.Namn ...
you can only join tables, not a table to a column
September 14th, 2012, 01:58 PM
-
Originally Posted by JacekVR
Yes it was the reason. Thank you.
I am a bit ahead but now the error is:
#1142 - SELECT command denied to user 'XXXXXX' for table 'Namn' although the sentence is:
SELECT * FROM Dammreg INNER JOIN Damm_vk.Namn ON Dammreg.DNAMN LIKE CONCAT('%', Damm_vk.Namn, '%');
Yes. Now it works. Thanks a lot!