0

I wanted to perform a select with join that fetched all the data from the two tables but that the second had a prefix to identify that the data is hers, for example I have table1 with column "name" and table2 also with column " name", I wanted to have a select select that was something like this:

SELECT 
    table1.* AS table1, 
    table2.* AS table2...

I did some research and I don't think it's possible, but maybe someone has a solution for this.

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TiagoR
  • 11
  • 1
  • 7
    SELECT * is bad and lazy coding. Avoid it! Define fields you are about to fetch, even if you'd need them all. – ex4 Apr 26 '22 at 17:02
  • only using dynamic SQL – Lamak Apr 26 '22 at 17:02
  • 2
    @ex4: This is untrue. SELECT * is completely fine when you're sure you want to select all columns. – Jonas Metzler Apr 26 '22 at 17:03
  • dynamic sql, or build your select concatenating it together in excel, something like that – Andrew Apr 26 '22 at 17:03
  • 4
    @ex4 Columns not "fields" – John Cappelletti Apr 26 '22 at 17:05
  • 1
    @JonasMetzler, not to belabor this opinionated discussion but see many SO and SE posts discussing the use of `SELECT *` : [here](https://stackoverflow.com/q/3639861/1422451), [here](https://stackoverflow.com/questions/65512/which-is-faster-best-select-or-select-column1-colum2-column3-etc), [here](https://stackoverflow.com/questions/3180375/select-vs-select-column), [here](https://softwareengineering.stackexchange.com/questions/234657/why-is-select-from-table-considered-bad-practice), and [here](https://dba.stackexchange.com/questions/220216/select-why-is-it-an-antipattern). – Parfait Apr 26 '22 at 17:17
  • @Parfait: No one denies a select * is bad in many cases. But when you're quite sure about your table and that you want to select all columns, it's completely fine. You can by the way confirm this point reading the links you've posted ;) – Jonas Metzler Apr 26 '22 at 17:22
  • I have no idea what this question is about. Please add table definitions, sample data and expected outcome as text and read https://stackoverflow.com/help/how-to-ask – P.Salmon Apr 27 '22 at 06:58

0 Answers0