I want all posts of type 'ajde_events' as a row each with a column for some basics from the post table and some ( not all ) associated postmeta values. I have cribbed the following from this post How to display multiple Post meta_key/meta_values by SQL query but as the op says in a comment it only returns a single row ( which seems to be the row where the location is a string starting with "Z" which I suspect is the "Highest" i.e. maximum string.
SELECT p.ID, p.post_title,
MAX(IF(PM.meta_key = 'evcal_location', PM.meta_value, NULL)) AS location,
MAX(IF(PM.meta_key = 'evcal_srow', PM.meta_value, NULL)) AS start_time
FROM wp_posts AS p
LEFT JOIN wp_postmeta AS pm ON p.ID = pm.post_id
WHERE post_type = 'ajde_events' AND post_status = 'publish'
ORDER BY p.ID
How do I get a row for each relevant post?
WP_Query
to do this, it will also be much simpler than messing about with MySQL. Let the PHP do the work and build the csv for you.