0

How can I create two aliases for a table containing a , separator in MySQL?

For example:

SELECT b.*,a.* FROM `tbl_users` a,b where a.id=b.parent_id.
Realitätsverlust
  • 3,941
  • 2
  • 22
  • 46
Venkatesh
  • 108
  • 1
  • 10
  • you'll probably have to clarify your question along with adding a few examples of things you tried in order to receive any help. You can always update your question. Welcome to stack overflow, recommended reading: http://stackoverflow.com/help/how-to-ask – Dan Beaulieu May 12 '15 at 12:06
  • `SELECT b.*,a.* FROM tbl_users a, tbl_users b where a.id=b.parent_id`? Whatever good this may do. – Uwe Allner May 12 '15 at 12:07
  • possible duplicate of [How do I create a table alias in MySQL](http://stackoverflow.com/questions/1890155/how-do-i-create-a-table-alias-in-mysql) – Bud Damyanov May 12 '15 at 14:04

1 Answers1

0

Looks like you are doing some self join and you can do as

select
a.*,b.* from tbl_users a
left join tbl_users b on a.id=b.parent_id

If you only want matching records then make it an inner join instead of left join

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63