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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Cannot connect to MySQL database when using a SQL statement

The connection when connecting straight to the database works perfectly. However, when I add a SQL statement in the connection, it does not work. It has worked previously when using a SQL statement, so there must be something wrong with the current one I am trying to use? I cannot seem to figure it out though. Please help!! 🙂 

 

Here is the statement:

SELECT
trim(P.policyNumber) AS 'Policy number',
PH.title AS 'Policy stage',
PH._policyHistoryInterfaceTypeEnum AS 'Policy stage type',
PH.created_at AS 'Policy stage created at',
PH.updated_at AS 'Policy stage updated at',
PH.deleted_at AS 'Policy stage deleted at',
P.statusEnum AS 'Policy status',
P._policyTypeEnum AS 'Policy type',
P.premium AS 'Policy premium',
P.excess AS 'Policy excess',
P.proRataAmount AS 'Policy prorata',
P.saleDate AS 'Policy sale date',
P.inceptionDate AS 'Policy inception date',
P.debitOrderDate AS 'Policy debit order date',
P.firstDebitDate AS 'Policy first debit date',
P.proRataDate AS 'Policy prorata date',
P.cancellationDate AS 'Policy cancellation date',
CONCAT(U.firstName, ' ', U.lastName) AS 'Client name',
U.dateOfBirth AS 'Client date of birth',
U.genderTypeEnum AS 'Client gender',
U.created_at AS 'Client created at',
U.updated_at AS 'Client updated at',
U.deleted_at AS 'Client deleted at',
(SELECT emailAddress FROM user_leads WHERE LH._leadId = user_leads._id) AS 'Client email',
(SELECT phoneNumber FROM user_leads WHERE LH._leadId = user_leads._id) AS 'Client phone number',
(SELECT heatDate FROM user_leads WHERE LH._leadId = user_leads._id) AS 'Client heat date',
(SELECT sourceTypeEnum FROM user_leads WHERE LH._leadId = user_leads._id) AS 'Client source',
CONCAT(UA.firstName, ' ', UA.lastName) AS 'Admin name',
(SELECT name FROM providers WHERE P._providerId = providers._id) AS 'Provider name',
(SELECT statusEnum FROM providers WHERE P._providerId = providers._id) AS 'Provider status',
PU.policyNumber AS 'Policy number 2',
PU.statusEnum AS 'Policy status 2',
PU.premium AS 'Policy premium 2',
PU.inceptionDate AS 'Policy inception date 2',
PU.debitOrderDate AS 'Policy debit order date 2',
PU.fullName AS 'Client name 2',
PU.phoneNumber AS 'Client phone number 2',
PU.emailAddress AS 'Client email 2'
FROM
policy_histories AS PH
LEFT JOIN policies AS P ON
PH._policyId = P._id
LEFT JOIN user_clients AS UC ON
PH._clientId = UC._id
LEFT JOIN users AS U ON
PH._clientId = U._userId
LEFT JOIN user_admins AS UA ON
PH._adminId= UA._id
LEFT JOIN lead_histories AS LH ON
PH._policyId = LH._policyId
LEFT JOIN policy_uploads AS PU ON
PH._policyId = PU._policyId

 

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Have you solved your issue by now? If you have, could you please help mark the correct answer to finish the thread? Your contribution will be much appreciated.

 

Regards,

Jimmy Tao

v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

What is the error message? In addtion, you can simplify your sql statement using statement like "select from where". You can do "join" operations in query editor.

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.