Results 1 to 8 of 8
  1. #1
    Vexorg is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    2

    How query mutiple entities within a single column?

    Hello, i know this is very simple but please bare with me.



    tablename= pref
    Code:
    Email	TNID 	First 	Last
    email1.com	1	John	Walk
    email2.com	2	Tom	Morgan
    email3.com	3	Beth	Ann
    email4.com	4	Sally	Jones
    email5.com	5	Martha	Johnson
    email6.com	6	Jill	Smith
    email6.com	7	Amanda	Soler
    email7.com	8	Joe	Money
    Lets say i wanted to use to query the following data using the "TNID" field and i wanted to search using THNID=1,2,3,4.

    These would be the results:
    Code:
    Email	TNID 	First 	Last
    email1.com	1	John	Walk
    email2.com	2	Tom	Morgan
    email3.com	3	Beth	Ann
    email4.com	4	Sally	Jones

    How would i create a query to do this in acess? I understand its similar to this but im not sure the exact way to do it in access...

    select email,tnid,first,last
    from pref
    where tnid like 1,2,3,4

    Help!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Two ways

    where tnid In(1,2,3,4)

    where tnid = 1 OR tnid = 2 OR tnid = 3 OR tnid = 4
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Paul,

    is there some 'short' documentation on that usage of the Subquery? I've only used it in the full context (select...). If there are other shortcuts like that, is there a site that explains?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'm not clear what you mean, as there is no subquery. I just posted the WHERE clause; the rest would still need to be there:

    select email,tnid,first,last
    from pref
    where tnid In(1,2,3,4)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pbaldy View Post
    I'm not clear what you mean, as there is no subquery. I just posted the WHERE clause; the rest would still need to be there:

    select email,tnid,first,last
    from pref
    where tnid In(1,2,3,4)
    you used ''IN()'' paul. that's what I meant. it is not a subquery per-se, but it is almost the same concept.

  6. #6
    Vexorg is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    Two ways

    where tnid In(1,2,3,4)

    where tnid = 1 OR tnid = 2 OR tnid = 3 OR tnid = 4

    What if i have a list of like 300 items, that are in an excel column, how can i do this so it dont have to manually type this stuff. My guess is just running a function to consolidate the cells.

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    where tind betwee 1 and 300

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ah, a moving target. If the Excel file is linked to the Access db, you should be able to join the Excel "table" to the Access table in your query and restrict the items returned to those in the Excel file:

    SELECT...
    FROM AccessTable INNER JOIN ExcelTable ON AccessTable.FieldName = ExcelTable.FieldName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Validating mutiple entry in a subform
    By Grooz13 in forum Forms
    Replies: 1
    Last Post: 08-09-2010, 06:53 AM
  2. auto populate mutiple fields
    By jomoan58 in forum Access
    Replies: 1
    Last Post: 07-23-2010, 01:03 PM
  3. Searching mutiple tables
    By mbolster in forum Access
    Replies: 8
    Last Post: 07-06-2010, 10:16 AM
  4. Replies: 7
    Last Post: 04-27-2010, 02:47 PM
  5. Replies: 1
    Last Post: 08-21-2009, 06:52 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