Questions tagged [mysql-error-1066]

MySql Error #1066: Not unique table/alias: '%s'

In a MySql query, if a table name or an alias is not unique you will get the following error:

MySql Error #1066: Not unique table/alias: '%s'

The following query is not correct and will throw an error:

SELECT *
FROM yourtable, yourtable
WHERE ...

here we are joining yourtable with itself, but the same table name is used twice. We need to give every table a distinct alias:

SELECT *
FROM yourtable AS a, yourtable AS b
WHERE ...

The same error could be thrown if the same alias is used twice:

SELECT *
FROM table1 AS a, table2 AS a
WHERE ...
26 questions
52
votes
3 answers

Not unique table/alias

I get the error ERROR 1066 (42000): Not unique table/alias: I cant figure out whats wrong with it. SELECT Project_Assigned.ProjectID, Project_Title, Account.Account_ID, Username, Access_Type FROM Project_Assigned JOIN Account   ON…
Malcr001
  • 8,179
  • 9
  • 44
  • 57
24
votes
4 answers

Why does this SQL code give error 1066 (Not unique table/alias: 'user')?

This is my table structure: The error message is: #1066 - Not unique table/alias: 'user' The following is my code. SELECT article.* , section.title, category.title, user.name, user.name FROM article INNER JOIN section ON article.section_id =…
neobeacon
  • 283
  • 1
  • 5
  • 9
6
votes
1 answer

Why does this SQL code give error 1066 (Not unique table/alias: 'customer')?

Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer')? SELECT customer.id, customer.firstName, account.id FROM customer, account INNER JOIN customer ON customer.id = account.customerId ORDER BY customer.id
aadersh patel
  • 709
  • 3
  • 8
  • 9
4
votes
2 answers

Two left joins and a union in MySQL

I'm trying to do a pretty complex query in MySQL; complex for me, at least. Here's an example of what I'm trying to do: SELECT * FROM friends LEFT JOIN users ON users.uid = friends.fid1 LEFT JOIN users ON users.uid = friends.fid2 WHERE (friends.fid1…
Josh Smith
  • 14,674
  • 18
  • 72
  • 118
3
votes
2 answers

Mysql JOIN of four tables with two key tables

I hate to admit it by my knowledge of MySQL is lacking when it comes to the more complex queries. Essentially I have four tables two of them contain the data I want to return, and two are relational tables linking the data. Table A is present just…
Brook Julias
  • 2,085
  • 9
  • 29
  • 44
2
votes
5 answers

Joining Several tables at once:

I'm using the following SQL statement: SELECT reply.id, reply.content, author.username FROM thread, reply, author JOIN thread_reply ON thread.id = thread_reply.thread_id JOIN reply ON thread_reply.reply_id = reply.id JOIN author_reply ON thread.id =…
john mossel
  • 2,158
  • 5
  • 24
  • 39
1
vote
1 answer

Error # 1066 - not a unique table / alias in MySQL

Good afternoon, I’m trying to fulfill the request while writing an error. Error # 1066 does not quite understand how it can be fixed in my particular case. Perhaps the problem is that I connect to the table several times and need an alias. SELECT…
1
vote
4 answers

Selecting certain tagged posts and their authors

How can you join these 5 tables together: tag: id, name author: username, id thread_tags: thread_id, tag_id thread: id, content author_threads: author_id, thread_id (I also have a table called author_tags (tag_id, author_id), but I dont think thats…
john mossel
  • 2,158
  • 5
  • 24
  • 39
1
vote
1 answer

Help with MySQL Query syntax: ERROR #1066 - Not unique table/alias

I have four tables, user, user_billingprofile, user_shippingprofile, and user_address. user: userId, dateCreated user_billingprofile: userId, address user_shippingprofile: userId, address user_address: random address crap Here is the query I have to…
Derek Adair
  • 21,846
  • 31
  • 97
  • 134
1
vote
1 answer

join on three tables? Error in phpMyAdmin

I'm trying to use a join on three tables query I found in another post (post #5 here). When I try to use this in the SQL tab of one of my tables in phpMyAdmin, it gives me an error: #1066 - Not unique table/alias: 'm' The exact query I'm trying to…
EmmyS
  • 11,892
  • 48
  • 101
  • 156
1
vote
3 answers

SQLSTATE Error Syntax error or access violation: 1066 Not unique table/alias: 'users_sessions'

I've got an error with a simple query using a join. My query : SELECT users_sessions.user_id AS users_sessions_user_id, users.last_name AS users_last_name, users.first_name AS users_first_name FROM prefix_users_sessions AS…
moDevsome
  • 189
  • 2
  • 16
0
votes
0 answers

I have a problem with this query, it says that " Not Unique table/alias 'ownertbl' " what should I do?

DELETE ownertbl.*, motorcycletbl.*, transactiontbl.* from (ownertbl INNER JOIN motorcycletbl on ownertbl.plate_no = motorcycletbl.plate_no) INNER JOIN transactiontbl on motorcycletbl.plate_no = transactiontbl.plate_no , (ownertbl INNER JOIN…
0
votes
0 answers

error 1066 - Generate backup by mysqldump in mariaDb, name of duplicate views

Command to generate the backup *mysqldump.exe --host=10.10.10.1 --protocol=tcp --user=user --password=****** --column-statistics=0 --port=3300 --default-character-set=utf8 database > c:/Temp/backup.SQL* Generate the error: Got error: 1066: Not…
0
votes
1 answer

ERROR 1066 (42000): Not unique table/alias: 'mp' OUTER JOIN in mysql

i have a problem converting my informix db to mysql. i got most things done but some functions just dont work. DELIMITER // CREATE PROCEDURE mw_getsvid(mwid INT) RETURNS INT BEGIN DECLARE svId INT; SELECT sv.ID INTO svId FROM messwert AS mw,…
itsme
  • 23
  • 4
0
votes
2 answers

Not unique table/alias (42000)

I get the error ERROR 1066 (42000): Not unique table/alias: 'STUDENT_TBL' select STUDENT,DATE,MARK from Assessments inner join STUDENT_TBL on Assessments,ID_STUDENT=STUDENT_TBL,STD_ID inner join Visit_log,ID_STUDENT=STUDENT_TBL,STD_ID where…
1
2