0

I've used it for many years, but I don't what it's called.

Example:

SELECT u.*, ug.group_name
FROM User u
LEFT JOIN user_group ug ON ug.group_id = u.group_id

What is this short reference name called in MySQL?

I've to use it with the CodeIgniter query builder, so I don't have to write it with every join function.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 5
    What *short reference name*? Do you mean the `u` and `ug`? Those are [aliases](https://en.wikipedia.org/wiki/Alias_(SQL)). – Ken White Jun 29 '19 at 17:24
  • https://stackoverflow.com/questions/198196/when-to-use-sql-table-alias – Sam M Jun 29 '19 at 17:31
  • Read about the syntax of the [`SELECT`](https://dev.mysql.com/doc/refman/5.7/en/select.html) statement in the [MySQL documentation](https://dev.mysql.com/doc/refman/5.7/en/). – axiac Jun 29 '19 at 17:39
  • 1
    As you now know, it's called an "alias". It was a fair question - I don't know why folks are marking you down :( As Bill Karwin pointed out, other names for this particular alias are "correlation name" and "table alias". – paulsm4 Jun 29 '19 at 19:22
  • I didn't downvote, but I suppose someone thinks this is a trivial question that is easily answered by reading practically any reference on SQL syntax. – Bill Karwin Jun 29 '19 at 19:29
  • @BillKarwin I did read briefly but since I forgot it what it's called I think I didn't know where to look. – Faizan Anwer Ali Rupani Jun 30 '19 at 18:23
  • If I had forgotten the term, I would have looked in reference documentation for the syntax of a `SELECT` query: https://dev.mysql.com/doc/refman/8.0/en/select.html – Bill Karwin Jun 30 '19 at 18:24
  • Good for you. I know you're an experienced programmer so you know where to look exactly. Not everyone has field experience as yours. Be considerable to others – Faizan Anwer Ali Rupani Jun 30 '19 at 18:28
  • I'm not mocking you. I'm suggesting that if you forget a term or a detail of syntax, then it's a logical place to look because the thing you are looking for is a common part of a SELECT statement. It's also a good idea to explore the online docs for the product you're using. I've been using MySQL for many years, and I still look up syntax practically every day. It's easier to use doc for reference than to keep it all in your head. – Bill Karwin Jun 30 '19 at 18:31

2 Answers2

3

It is called an alias for tables and columns.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nbk
  • 45,398
  • 8
  • 30
  • 47
1

When used for a column, it's called an alias.

When used for a table, it's officially called a correlation name in the ANSI SQL specification.

But most people call that a "table alias." Even the MySQL manual doesn't call it a correlation name.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828