Hi,

I have a 'persons' table, an 'answer' table and a 'token' table.

The token table contains matching unique identifiers from the persons table and the answers table.

In my query I want to join the persons table with the answers but I don't know how to proceed since they don't contain matching identifier and I would have to check the token table somehow in the query.

I did try to create a trigger in mysql admin to update the persons table with the corresponding token value but my query resulted in a "#1419 - You do not have the SUPER privilege". As this failed I gather that I have to create this query or is there a better solution?

Cheers
Adam

Recommended Answers

All 7 Replies

If you can show the structure and some data, we can help you write the query.

I want to join everything from the persons table and anwers table.

Token table:
--------token---------unikid------
------aaaBBB324Cc-----777777

Persons table:
-----id--------unikid----------postnummer---------born--...........
-----1---------777777-------------19552--------1978-02-12 ..........

Answers table:
-----token-------question1a1-------question1a2-------question2------........
--aaaBBB324Cc---------Y----------------NULL--------------Y-----........

Cheers!
Adam

SELECT * 
FROM Persons p, Token t, Answers a
WHERE p.unikid = t.unikid
AND t.token = a.token

Brilliant!! Thanks alot!

Could you help me rewrite the select statement if I want for example count all the occurrences of 'Y' in column question1a1 from the answers table AND get a date from the Persons table.

The date from the persons table should of course fullfill the condition you wrote above
FROM Persons p, Token t, Answers a WHERE p.unikid = t.unikid AND t.token = a.token)

Cheers
/Adam

Something like this?

SELECT COUNT(*)
FROM Persons p, Token t, Answers a
WHERE p.datecolumn = 'yyyy-mm-dd'
AND p.unikid = t.unikid
AND t.token = a.token
AND a.question1a1 = 'Y'
GROUP BY a.question1a1

Next time better start a new discussion thread, and reference this one.

Thank you!!

/Adam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.