mysqlsqlmysql-error-1054

Surely it is a stupid syntax mistake but I am a beginner with sql: 1054. Unknown column Error


I have the following query:

SELECT
    INIZIO.idinizio AS id,
    inizio,
    fine,
    barca
FROM
    (
        (
        SELECT
            ID AS idinizio ,
            meta_value AS inizio,
            term_taxonomy_id AS barca
        FROM
            wp_posts
        INNER JOIN wp_postmeta ON(
                ID = post_id AND post_type = 'tribe_events' AND meta_key = '_EventStartDate' AND(
                    post_status = 'publish' OR post_status = 'private'
                )
            )
        INNER JOIN wp_term_relationships ON(
                ID = object_id
            )
        ) AS INIZIO
INNER JOIN
        (
        SELECT
            ID AS idfine,
            meta_value AS fine
        FROM
            wp_posts
        INNER JOIN wp_postmeta ON(
                ID = post_id AND post_type = 'tribe_events' AND meta_key = '_EventEndDate' AND(
                    post_status = 'publish' OR post_status = 'private'
                )
            )
        ) AS FINE
ON (idinizio = idfine)
)

And when I run it I get the following error:

Error Code: 1054. Unknown column 'idinizio' in 'field list'

Image of my table

Why am I getting this error?

Surely it will be a beginner's mistake in the subquery or in some table alias.

UPDATE:

.. I realized now that I have reversed all the AS clauses .. I fixed and now gives me this error:

#1054 - Colonna sconosciuta 'posts.idinizio' in 'on clause'

UPDATE: I made the table prefixes wrong and I fixed it, now everything works, thank you very much for making me notice errors!


Solution

  • You should replace idinizio column with ID as ON (INIZIO.ID = FINE.idfine) at the bottom part, since you already aliased that column as ID in the above inner query.