Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL select join: is it possible to prefix all columns as 'prefix.*'?
    primarykey
    data
    text
    <p>I'm wondering if this is possible in SQL. Say you have two tables A and B, and you do a select on table A and join on table B:</p> <pre><code>SELECT a.*, b.* FROM TABLE_A a JOIN TABLE_B b USING (some_id); </code></pre> <p>If table A has columns 'a_id', 'name', and 'some_id', and table B has 'b_id', 'name', and 'some_id', the query will return columns 'a_id', 'name', 'some_id', 'b_id', 'name', 'some_id'. Is there any way to prefix the column names of table B without listing every column individually? The equivalent of this:</p> <pre><code>SELECT a.*, b.b_id as 'b.b_id', b.name as 'b.name', b.some_id as 'b.some_id' FROM TABLE_A a JOIN TABLE_B b USING (some_id); </code></pre> <p>But, as mentioned, without listing every column, so something like:</p> <pre><code>SELECT a.*, b.* as 'b.*' FROM TABLE_A a JOIN TABLE_B b USING (some_id); </code></pre> <p>Basically something to say, "prefix every column returned by b.* with 'something'". Is this possible or am I out of luck?</p> <p>Thanks in advance for your help!</p> <p>EDIT: advice on not using SELECT * and so on is valid advice but not relevant in my context, so please stick to the problem at hand -- is it possible to add a prefix (a constant specified in the SQL query) to all the column names of a table in a join?</p> <p>EDIT: my ultimate goal is to be able to do a SELECT * on two tables with a join, and be able to tell, from the names of the columns I get in my result set, which columns came from table A and which columns came from table B. Again, I don't want to have to list columns individually, I need to be able to do a SELECT *.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload