#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    3
    Rep Power
    0

    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 03:29 AM. Reason: clarification
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. Hockey face
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    St. Catharines, Canada
    Posts
    8,147
    Rep Power
    1317
    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
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    3
    Rep Power
    0
    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, '%');
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    FROM Dammreg INNER JOIN Damm_vk.Namn ...

    you can only join tables, not a table to a column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    3
    Rep Power
    0
    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!

IMN logo majestic logo threadwatch logo seochat tools logo