0

I am wanting to select 1 column from my select statement as but then leave the rest as is so:

SELECT tbl_user.reference AS "reference", * FROM tbl_user JOIN tbl_details ON.....

Is this possible?

puks1978
  • 3,667
  • 11
  • 44
  • 103

2 Answers2

1

Yes. You can use double quotes like that to create a column alias. You can SELECT a column twice (or more) in your SELECT list.

Try something like this, where you can give each "reference" column its own alias:

 SELECT u.reference AS UserReference,
        d.reference as DetailsReference,
        u.id, /*etc etc*/
 FROM   tbl_user AS U
 JOIN   tblDetails AS D ON ....           

You mention in the comments that you want all columns from each table, while being able to distinguish between the reference columns(likely named the same in both tables). Suggest NOT using SELECT *, as it's an anti-pattern. It's most beneficial to specify your column list in your SELECT statement, and do your query engine a favour of not having to look up the list of columns on each table.

Community
  • 1
  • 1
p.campbell
  • 98,673
  • 67
  • 256
  • 322
0

If you just want one column, this will work:

SELECT SELECT tbl_user.username AS "username" FROM tbl_user JOIN tbl_details on tbl_user.key LIKE tbl_details.key

What do you mean by "but then leave the rest as is "?

Sinthia V
  • 2,103
  • 2
  • 18
  • 36
  • I just edited the question to be more realistic and make more sense. I need all columns from both tables but both tables have a column reference which has different values and the one displayed in my output is the wrong one. I mean leave rest as is as I dont want to be writing tbl_user.name, tbl_details.id etc for all columns as there are a lot of columns in each table – puks1978 Dec 05 '11 at 04:01