Change column names "id" of a sql return

0

I want to perform a SQL query and change the name of the columns in the result because I have 3 columns id .

Currently my SQL looks like this:

SELECT * 
FROM shopweb_tipo as st 
INNER JOIN shopweb_categoria AS sc 
INNER JOIN shopweb AS s 
WHERE s.categoria = sc.id 
    AND s.tipo = st.id

I've tried to do this, but I did not get results.

SELECT * 
FROM shopweb_tipo as st 
INNER JOIN shopweb_categoria AS sc 
INNER JOIN shopweb AS s 
WHERE s.categoria = sc.id 
    AND s.tipo = st.id 
    AND shopweb.id as "id_shopweb"
    
asked by anonymous 08.12.2017 / 18:03

1 answer

1

You have to describe the columns instead of putting * and give them an alias example:

SELECT
    st.id AS [apelido para o id],
    [demais_campos st],
    sc.id AS [apelido para o id],
    [demais_campos sc],
    s.id AS [apelido para o id],
    [demais_campos s]
FROM
    shopweb_tipo AS st
INNER JOIN shopweb_categoria AS sc
INNER JOIN shopweb AS s
WHERE
    s.categoria = sc.id
AND s.tipo = st.id

Of course, and call the other fields in the query as well.

Another way is to search only the id field and then the other fields, but the ID field will come twice, one with alias another without

SELECT
    st.id AS [apelido para o id],
    st.*,
    sc.id AS [apelido para o id],
    sc.*,
    s.id AS [apelido para o id],
    s.*
FROM
    shopweb_tipo AS st
INNER JOIN shopweb_categoria AS sc
INNER JOIN shopweb AS s
WHERE
    s.categoria = sc.id
AND s.tipo = st.id
    
08.12.2017 / 18:07