Results 1 to 5 of 5
  1. #1
    sireesha is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    50

    Query for Joins

    HI,



    I have 4 tables with relations. in 3 tables i have a data and in 4th table no data. i have to write a query for to display data from 3 tables if 4th table is not necessary. if 4th table has a data need to check the relations then display otherwise 3 tables data is shown as a result. 4th table fields also included in the query.

    My query is:

    FROM
    (a INNER JOIN (b INNER JOIN( c ON (b.ID = c.ID)
    AND (b.ID1 = c.ID1)) ON (a.ID1 = c.ID1)
    AND (a.iD1 = b.ID1))
    left JOIN d ON (c.PURCHASE_ID = d.PURCHASE_ID)
    AND (b.PURCHASE_ID = d.PURCHASE_ID)

    i want to exclude d table if no data is there. if data is there then check above conditions.

    so i'm using left join.

    but it gives error.

    when in leftjoin and condition is removed then it will display result.

    but i want after and condition also.

    Please help me.

    Regards,
    Sireesha.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    You can't have an if/then in your query if it's an actual database object. You'd basically have to open the query modify the SQL statement, save the query then re-open the query (if you were doing it with code).

    If you're willing to see blank fields where the D table would be that's a different matter and you can do it in your query.

    if However you're creating a dynamic dataset in some VB script you can certainly modify the SQL statement to properly create a set of data.

  3. #3
    sireesha is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    50

    left join

    Quote Originally Posted by rpeare View Post
    You can't have an if/then in your query if it's an actual database object. You'd basically have to open the query modify the SQL statement, save the query then re-open the query (if you were doing it with code).

    If you're willing to see blank fields where the D table would be that's a different matter and you can do it in your query.

    if However you're creating a dynamic dataset in some VB script you can certainly modify the SQL statement to properly create a set of data.

    Hi,

    I have given only join conditions (from clause only). if i have used left join it gives error how do rectify it. all 3 tables are inner join i.e., includes data. in the 4th table not mandatory. if the data is in that table it will take otherwise it shows blank, these table fields are includes in this query.

    Please help me asap

    Regards,
    Sireesha.

  4. #4
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    I think that (in design view) if you set up the tables and drag relationships between ID1 you could make the joins left (double click the join)
    This is kind of similar to what I have. The one the farthest to the left has all of the project codes that I will use. Maybe you want to leave the first 2 normal, play around with it.

    Click image for larger version. 

Name:	Capture1.PNG 
Views:	8 
Size:	6.3 KB 
ID:	13039

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    You can do this with a 'pre' query.

    Create your inner join query first (between dbo_project, dbo_vw_projecteeic and dbo_vw_projectrema...) Save that query first.

    Then create a second query based on your Inner query and the table dbo_vw_projectteam.

    This way you'll get only the records that have values in all three tables and any relevant data in table dbo_vw_projectteam that relates to those items.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-06-2013, 11:37 PM
  2. Replies: 5
    Last Post: 11-05-2012, 08:33 AM
  3. Replies: 15
    Last Post: 10-22-2012, 06:06 PM
  4. Joins
    By jlgray0127 in forum Forms
    Replies: 2
    Last Post: 11-11-2011, 05:04 PM
  5. Need Help with Joins
    By usa_dreamer2002 in forum Queries
    Replies: 3
    Last Post: 01-31-2011, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums