Jump to content

mySQL join query problem


murfitUK
 Share

Recommended Posts

Got two tables: Document and AccessDocument fields include documentCode and documentMethod where the documentCode is something like 'st01' and documentMethod is either 'free' or 'paid' (free docs are available to all members, but paid ones have to be paid for).Access fields include the documentCode from the Document table and a member username which is inserted into the table after a member has paid for access to a document.The user will click on a link 'createPDF.php?itemid=st01' (for example).I need a query to find out if the user is allowed to access this document. He can access:1) if it is free (can be found from the Document table) or2) if it is a paid-for doc then can be found from the Access table IF AND ONLY IF there is a row containing the code (eg st01) and the username.(I know the username from a $_SESSION variable when logged in.)Can this be done in one query? So far, I run it with two - the first checks if it is free. If not, then it checks if the user has an entry with that docCode in the Access table. I'm sure it can be done with a join, but I'm going round in circles trying to figure it out.Any help much appreciated.

Link to comment
Share on other sites

You'll need to use a full outer join, and join the tables on the document code. You can put the user name in the where clause. I don't think this will return only one row though, a full outer join is like a union between a left outer join and a right outer join.http://en.wikipedia.org/wiki/Join_(SQL)#Full_outer_join

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...