Divin3n
Divin3n

Reputation: 19

SQL substring statement

i stumbled across this kind of SQL query which im not familiar with. what exaxcly is the "new" thing after building the select statement ?

substring((select group_concat(new.card_number,0x0a,new.card_holdername) from 
(select id,card_number,card_holdername from credit_cards) new where new.id=1), 
1, 300)

Upvotes: 0

Views: 41

Answers (2)

Nedzad G
Nedzad G

Reputation: 1037

new is the alias, in your example it is alias of this select:

(select id,card_number,card_holdername from credit_cards) new 

So, these are the references from your new table:

new.card_number,0x0a,new.card_holdername ..

Upvotes: 0

Kamil Gosciminski
Kamil Gosciminski

Reputation: 17177

In SQL every SELECT statement returns a table. Every table needs to have a name. This is called an alias. You can do the same thing with columns giving them another name for a particular query you are executing


In your example intermediate table was called new and the query to create it is:

select id,card_number,card_holdername from credit_cards

In an outer query you can then reference columns from this new table like so:

new.id
new.card_number
new.card_holdername

Upvotes: 1

Related Questions