![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: mysql, subqueries |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| ||||
| I dont get what your asking, could you maybe reword it a little? |
| ||||
| Would you mind: 1) Giving the database structure (via a data dictionary, for example). 2) Indicate which version of SQL you're running, including version. MySQL, for example, has widely different capabilities between 4.x and 5.x. 3) State the exact question that your query ought to answer. |
| |||
| I'm not familiar with what your doing there (Don't know the keywords all or any) but how sub-queries work is they build a temporary table that your main table can join to. So if you did: Select UserID, UserName from User Where StatusID = 1 You could Join with SubQuery to Parent Query on UserID: Select WebSiteName, UserID from WebSite Left Outer Join (Select UserID, UserName from User Where StatusID = 1) UserTableJoiner on UserTableJoiner.UserID = WebSite.UserID This would join Website to User where User's Status = 1 You just have to think from the Inner to the Outer. Think of what you need to join to your parent query. The inner query will join to the outer query with the UserID - so our UserID has to be in the inner and outer queries and they will match. Then you could put that query in another sub-query and join with a master query: Select CompanyName, WebsiteID From Company Left Outer Join (Select WebsiteID, WebSiteName, UserID from WebSite Left Outer Join (Select UserID, UserName from User Where StatusID = 1) UserTableJoiner on UserTableJoiner.UserID = WebSite.UserID) WebsiteTableJoiner on WebsiteTableJoiner.WebsiteID = Company.WebsiteID You can see we added a WebsiteID as the Joining Field to join Company with Website. And you can go on and on and on - You could wrap this with Corporation, and Wrap that with World, etc... And a tip - try to use Sub-Queries in your From ![]() __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
| ||||
| Hmm.. ccoonen, you're talking about joining tables, no, that's not what i'm trying to do. It's my fault too for being confusing, sorry haha.. I basically want to find out how to use sub-queries on my query? And then once I got that, I want to put sub-query in a subquery that is in a query. Get it...? Kind of..? ![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |