After JOIN, if the two bits are duplicated, but all of them have to be shown, how can they be distinguished?

SELECT * FROM `product` AS p
      JOIN
        `store` AS s ON p.prod_id = s.prod_id

my join has realized that I need store"s name, icon and product"s name, icon
. What should I do?

this is what I show:

<? while($row = mysqli_fetch_array($data)){?>
      <?=$row["icon"];?>
      <?=$row["name"];?>
<?}?>
Mar.23,2021

SELECT
    p. NAME AS productName,
    p.icon AS productIcon,
    s. NAME AS storeName,
    s.icon AS storeIcon
FROM
    `product` AS p
JOIN `store` AS s ON p.prod_id = s.prod_id

in fact, there are two columns with the same name in the result, but this is not easy to parse. You can use the alias (alias)

.
SELECT 
    table1.column1 AS column_alias1,
    table2.column1 AS column_alias2
FROM
    table1, table2;

so that the two columns column_alias1 and column_alias2 in the result are column1 of table1 and column1 of table2 , respectively.

you already know how to use the alias of a table, but you don't know that there are mixed aliases under the alias, of a column.

SELECT
    a.c1,
    a.c2 AS ca1,
    b.c2 AS ca2,
    b.c3
FROM
    table1 AS a,
    table2 AS b;

then the result will have four columns, C1 , ca1 , ca2 , c3 .

you can also mix the wildcard * , but this will put the column of the original name and alias together in the result, but it does not affect the parsing, as long as you know what you want.

Menu