We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,682 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
7
Replies
2 Weeks
Discussion Span
2 Months Ago
Last Updated
24
Views
Question
Answered
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
Moderator
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
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Brilliant!! Thanks alot!

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
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Thank you!!

/Adam

adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0829 seconds using 2.69MB