简体   繁体   中英

SELECT * AS {table_name}.{field_name}

Is it possible to write the following query so that instead of just field names, the result "keys" include the name of the table the fields belong to.

SELECT * FROM books

The result should look like:

| books.id | books.name | etc.
| 1        | She        |
| 2        | Lolita     |

你必须单独为它们添加别名..

SELECT id as 'books.id', name as 'books.name' FROM books
SELECT id as "books.id", name as "books.name" FROM books

If you plan query mysql via a programming language, all the mysql drivers I've come across have access to the table name(s) when retrieving result sets. So, you don't need to change your query to rename columns to include the table name...you can just do it with code.

In your programming language of choice, look for a function that has a name similar to "meta data". That's likely one of the functions you'll need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM