query that joins two tables depending on third table
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
Related Article: php mysql query wont work properly
is a PHP discussion thread by garyjohnson that has 3 replies, was last updated 4 months ago and has been tagged with the keywords: php, mysql, query.
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
If you can show the structure and some data, we can help you write the query.
pritaeas
Posting Prodigy
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86
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
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
SELECT *
FROM Persons p, Token t, Answers a
WHERE p.unikid = t.unikid
AND t.token = a.token
pritaeas
Posting Prodigy
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Months Ago by
pritaeas 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
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
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.
pritaeas
Posting Prodigy
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0