Results 1 to 5 of 5

Thread: Construction of a request

  1. #1
    Join Date
    Nov 2008
    Posts
    1,221

    Construction of a request

    I find it hard to build a query. Knowing the nickname of the user, I want to display the name of his group of assignment (attribute name of the table groups). The id attribute of the table groups is related to the attribute table id_object of users_groups.

    I thought about this query:

    select name from groups where id = (select id_group from users_groups where id_object = (select id_user from users where nickname = "foo");

    But is there not something cleaner and simpler than subqueries?

  2. #2
    Join Date
    Feb 2008
    Posts
    194

    Re: Construction of a request

    There are more simple:

    SELECT name FROM groups, users, user_groups WHERE id = id_groups AND id_object = id_user AND nickname LIKE "foo";

    If the three tables are in the same basis otherwise it must use the inner join

  3. #3
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Construction of a request

    To explain the problem, I changed in the post the unique identifier of the table users. Thus, id became id_user. But I am working on a relational database schema that I can not change. The complaint advised me logically generates this error message:

    # 1052 - Column 'id' in where clause is ambiguous

  4. #4
    Join Date
    May 2008
    Posts
    3,971

    Re: Construction of a request

    Add the table name like this:

    SELECT name FROM groups, users, user_groups WHERE groups.id = users_groups.id_groups AND users_groups.id_object = users.id_user AND nickname LIKE "foo";

    I added the name of the table for every id in case they were called id in all reality

    You can also give a name to each table in the FROM clause and, for simplicity:

    SELECT name FROM groups g, users u, user_groups ug WHERE g.id = ug.id_groups AND ug.id_object = u.id_user AND nickname LIKE "foo";

  5. #5
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Construction of a request

    Thank you switchblade327 for additional info. It works correctly. In fact this is straightforward.

Similar Threads

  1. Replies: 4
    Last Post: 11-01-2014, 10:14 AM
  2. Construction of the BO in Java EE
    By PARRISH in forum Tips & Tweaks
    Replies: 2
    Last Post: 27-07-2010, 06:14 AM
  3. Windows 7 new construction
    By SalVatore in forum Operating Systems
    Replies: 4
    Last Post: 18-03-2009, 10:31 PM
  4. Under construction google !
    By keithuk in forum Technology & Internet
    Replies: 2
    Last Post: 17-10-2008, 06:12 PM
  5. Replies: 3
    Last Post: 10-05-2007, 11:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,347,889.85665 seconds with 16 queries