Results 1 to 8 of 8
  1. #1
    gary223 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2011
    Posts
    6

    Help with SQL queries

    I've just started learning SQL and just wanted to check if my answers are correct.

    There are two tables Contacts and Departments. Create the following SQL queries.

    (i) Find all contacts who surname begins with D.

    SELECT * FROM contacts where surname like "d*";

    (ii) Find all contacts whose name is john and is older than 45.

    SELECT * FROM contacts where firstname like "john" and where age > 45;

    (iii) Delete all departments whose department head is Dana Black
    DELETE FROM departments
    WHERE DeptHead='Dana Black';

    (iv) Display all contacts that belong to the department description is maths
    SELECT * FROM contacts WHERE Dept_Description like "maths";

    (v) Add the following contact Jim White, age 33, phone: 123456789
    INSERT INTO contacts
    VALUES ('Jim', 'White', '33', '123456789');

    (vi) Write an SQL statement to create the contacts table


    CREATE TABLE contacts;

    It would be great if someone could help me out here or confirm my answers are correct. I don't have access to Microsoft Access at the moment (no pun intended) Thanks.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    1) do not use LIKE without having the need for an "*" symbol. always use "=". it's standard.

    2) access sql does not accept single quotes. doubles only.

    3) CREATE TABLE statements in access are called "DDE queries". Like other sql engines, I don't know if you can write these statements without spec'ing at least one field. My guess is NO. To my knowledge, you cannot run DDE statements in the access wizard unless the option is spec'd from the top menus. Similar to spec'ing a SELECT, APPEND, DELETE, etc..

  3. #3
    gary223 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2011
    Posts
    6
    Besides the quotes and lack of equals signs, are my answers correct?

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

    ............

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Quote Originally Posted by ajetrumpet View Post
    2) access sql does not accept single quotes. doubles only.
    In what situation? Queries "iii" & "v" should work exactly as they are (presuming all fields are text).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    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
    In what situation? Queries "iii" & "v" should work exactly as they are (presuming all fields are text).
    the query wizard does not accept single quotes, Paul. Or am I wrong about that. ???

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Don't know; I'll let you test this time.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    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
    Don't know; I'll let you test this time.
    i dont need to test, P. I KNOW what I'm talking about...

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

Similar Threads

  1. VBA vs Queries
    By TheDeceived in forum Access
    Replies: 6
    Last Post: 12-16-2011, 06:11 AM
  2. Sum Queries
    By Lilsug in forum Access
    Replies: 4
    Last Post: 12-17-2010, 08:45 AM
  3. Queries
    By MeganDoak in forum Queries
    Replies: 3
    Last Post: 04-22-2010, 12:13 AM
  4. how i can run a sum queries
    By ahmed-aljawad in forum Queries
    Replies: 3
    Last Post: 04-17-2010, 11:06 AM
  5. need help with queries
    By gromit95 in forum Queries
    Replies: 1
    Last Post: 02-06-2009, 06:50 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