Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
alandilworth
Regular Visitor

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 3
v-janeyg-msft
Community Support
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
v-janeyg-msft
Community Support
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)?

ALLUREAN
Solution Sage
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/




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.