Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-03-2009
Member
 
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?
Reply With Quote
  #2  
Old 21-03-2009
Member
 
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
Reply With Quote
  #3  
Old 21-03-2009
Member
 
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
Reply With Quote
  #4  
Old 21-03-2009
Member
 
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";
Reply With Quote
  #5  
Old 21-03-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Construction of a request"
Thread Thread Starter Forum Replies Last Post
Error parsing Request: The request subject name is invalid or too long. 0x80094001 (-2146877439) Dharitree Windows Security 4 11-01-2014 10:14 AM
Construction of the BO in Java EE PARRISH Tips & Tweaks 2 27-07-2010 06:14 AM
Windows 7 new construction SalVatore Operating Systems 4 18-03-2009 10:31 PM
Under construction google ! keithuk Technology & Internet 2 17-10-2008 06:12 PM
Certificate Request Processor - The request contains no cert templ BrianS Windows Server Help 3 10-05-2007 11:12 PM


All times are GMT +5.5. The time now is 08:02 AM.