0

I want to get all the data from table partner_orders which I am. But in addition to that, I want to get the columns displayName and email from table ds_user. ds_user id is the same as partner_orders dsUserId. So in the output in every array I want the email and displayName of that user with the same id to be added to the array.

However, with the way I have written the code below, I am getting all columns in partner_orders but I am not getting displayName and email added to it. What's the right way to do it

This is what I have written in JavaScript

  async getAllParenFinanceOrders() {
    const programOrders = await pool.query(
      `SELECT po.*, du."displayName", du."email"
      FROM partner_orders AS po 
      LEFT JOIN ds_user AS du ON du.id = po."dsUserId" `

    );
mark smith
  • 21
  • 5
  • Please provide test data (in each table), the actual results you are getting and the desired results for that data. All as formatted text - **no images**. Even better provide a [fiddle](https://dbfiddle.uk/?rdbms=postgres_13) and the desired results. NOTE: You should only select 1 database. – Belayer Oct 25 '21 at 17:31

1 Answers1

0

In Mysql you neeed to use backticks instead og double quotes see more about that When to use single quotes, double quotes, and backticks in MySQL

async getAllParenFinanceOrders() {
const programOrders = await pool.query(
  'SELECT po.*, du.`displayName`, du.`email`
  FROM partner_orders AS po 
  LEFT JOIN ds_user AS du ON du.id = po.`dsUserId`'

);
nbk
  • 45,398
  • 8
  • 30
  • 47