Forum Discussion

alandilworth's avatar
alandilworth
Regular Visitor
4 years ago

Primary key not importing when importing data from MySQL using SQL statement

I'm having a problem where the primary key of a table I import into Power Query using a SQL statement is not showing up. I have another table where I used a similar select statement and did not have this issue.

 

My SQL statement is below:

Select * from Pharmavail left join TerritoryContracts on entity = nameOfEntity and TerritoryContracts.newTerritoryID = Pharmavail.territory and (`month` between originalContractDate and endContractDate ||
`month` >= originalContractDate and endContractDate IS NULL);

 

When I run this query in Workbench the primary key is returned.  Additionally, on a similar query below I do not have this problem and the primary key imports without issue.
select * from Pharmavail left join ProductInfo on CONCAT('GD',Pharmavail.NDC)=ProductInfo.NDC WHERE (groupId = 'GALTCSH' or groupId = 'GALTCSH2' or groupId = 'GALTCSH3') and ((`month` between StartDate and EndDate) or (`month` >= StartDate and EndDate IS NULL));

Any insight will be greatly appreciated!

 

3 Replies

  • ALLUREAN's avatar
    ALLUREAN
    Solution Sage

    You can try to click on Refresh button (Refresh all) in PQ to see if this column will appear. Also, you can test instead of using * just to select only the PK column in your SQL query in PBI import

     

    Appreciate your Kudos !!!

    https://allure-analytics.com/

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Community Support

    Hi, alandilworth 

     

    Do you mean that the primary key column is not returned in PQ?

    Can you share the screenshot of the data obtained after returning the query in the data source and in powerbi(hide privacy)?

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Community Support

    Hi, alandilworth 

     

    Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution and you are welcome to share your solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your .pbix file after removing sensitive data.

     

    Best Regards,
    Community Support Team _ Janey