0

I have been researching trying to find the answer to this question but have been unsuccessful. I have a table in my database which contains a user's logon information. In my next column, I need it to pull the user's first name and last name based on the sign on information from the previous column. The 2nd column is pulling data from a different table though. I am a novice with SQL queries so I am unsure how I need to set this up.

This is my latest attempt to capture this information:

SELECT lognm_firstnm + lognm_lastnm 
FROM oslogname JOIN ns_medication 
USING (mlx_ubl);

An example of the output I am expecting is:

UBL              Employee Name
Kgarland         Karen Garland

The first column is pulling data from the table: mlx_ubl.ns_medication (this is the UBL column) and the second is pulling from the table: lognm_firstnm.oslogname + lognm_lastnm.oslogname (this is the Employee Name column).

  • 2
    The string concatenation operator in SQL is `||` - the `+` is for adding numbers –  Dec 06 '21 at 15:51
  • Check out the top answer here. I think it does a better job of answering than the postgres manual: [How to concatenate columns in a Postgres SELECT?](https://stackoverflow.com/questions/19942824/how-to-concatenate-columns-in-a-postgres-select) – JNevill Dec 06 '21 at 16:08
  • I was able to get the concatenation to work by using this command but my join is still not working SELECT concat(lognm_firstnm, lognm_lastnm) AS "Administering Provider Name" FROM oslogname – Karen Garland Dec 06 '21 at 17:34

1 Answers1

0
SELECT ns_medication.mlx_ubl AS "UBL", lognm_firstnm  || ' '|| lognm_lastnm AS "Employee Name"
FROM oslogname JOIN ns_medication 
USING (mlx_ubl);
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77