473,802 Members | 2,317 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Help - avoiding querying a query...

3 New Member
I'm working on a simple database that has 2 tables one called ITEMS, one called USERS. I'm tracking items being transfered between 2 users. in the ITEMS table I reference the sending user and receiving user by a numeric field ITEMUSERID and SENDTO that both refer to the USERID in the USERS table. I want to pull the description of both of these users in my result. I am able to do this using a stored query and then querying that query. I want to be able to do it in one step.

Here's what works..

Stored Query: ITEMS_LOCATION
(This pulls all the items and the "where they're coming from" description...)

SELECT USERS.DESCRIPTI ON, USERS.USERID, ITEMS.INFO, ITEMS.ITEMUSERI D, ITEMS.SENDTO
FROM ITEMS INNER JOIN USERS ON ITEMS.ITEMUSERI D = USERS.USERID;

(Then I execute the following query to get the "where the item is going" description in to the table)

SELECT ITEMS_LOCATIONS .DESCRIPTION, ITEMS_LOCATIONS .USERID, ITEMS_LOCATIONS .INFO, ITEMS_LOCATIONS .ITEMUSERID, ITEMS_LOCATIONS .SENDTO, USERS.DESCRIPTI ON
FROM ITEMS_LOCATIONS LEFT JOIN USERS ON ITEMS_LOCATIONS .SENDTO = USERS.USERID;

How can I acomplish this as one query?
Apr 9 '07 #1
4 1324
iburyak
1,017 Recognized Expert Top Contributor
1.
in the ITEMS table I reference the sending user and receiving user by a numeric field ITEMUSERID and SENDTO that both refer to the USERID in the USERS table

According to statement above table ITEMS has both columns ITEMUSERID and SENDTO.

2.

SELECT ITEMS_LOCATIONS .DESCRIPTION, ITEMS_LOCATIONS .USERID, ITEMS_LOCATIONS .INFO, ITEMS_LOCATIONS .ITEMUSERID, ITEMS_LOCATIONS .SENDTO, USERS.DESCRIPTI ON
FROM ITEMS_LOCATIONS LEFT JOIN USERS ON ITEMS_LOCATIONS .SENDTO = USERS.USERID;
According to query provided it looks like SENDTO is in a different table ITEMS_LOCATIONS .


Which one is correct?
Apr 9 '07 #2
chitownjohn69
3 New Member
ITEMS_LOCATIONS is the name of the stored query...
Apr 9 '07 #3
iburyak
1,017 Recognized Expert Top Contributor
Try this:


[PHP]SELECT U1.DESCRIPTION, U1.USERID, ITEMS.INFO, ITEMS.ITEMUSERI D, ITEMS.SENDTO,
U2.DESCRIPTION
FROM ITEMS INNER JOIN USERS U1 ON ITEMS.ITEMUSERI D = USERS.USERID
INNER JOIN USERS U2 ON ITEMS.SENDTO = USERS.USERID[/PHP]


Good Luck
Apr 9 '07 #4
chitownjohn69
3 New Member
Got me pointed in the right direction.. This works..

SELECT ITEMS_LOCATIONS .DESCRIPTION, ITEMS_LOCATIONS .USERID, ITEMS_LOCATIONS .INFO, ITEMS_LOCATIONS .ITEMUSERID, ITEMS_LOCATIONS .SENDTO, USERS.DESCRIPTI ON
FROM [SELECT USERS.DESCRIPTI ON, USERS.USERID, ITEMS.INFO, ITEMS.ITEMUSERI D, ITEMS.SENDTO
FROM ITEMS INNER JOIN USERS ON ITEMS.ITEMUSERI D = USERS.USERID]. AS ITEMS_LOCATIONS LEFT JOIN USERS ON ITEMS_LOCATIONS .SENDTO = USERS.USERID;

Thanks!
Apr 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2657
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about splitting up the XML into several XML documents (perhaps 50,000 per document) to be more efficient but this will make things a lot more complex because the searching needs to go accross all 500,000 records. Can anyone point me to some best practices...
5
2378
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to make up the finished part. The sub-parts can also be made up of sub-parts and those sub-parts can also be made up of sub-parts etc etc. All parts are contained within the same table and I have a seperate table
0
2627
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to find one, I'm posting the question in hope some one of you guys out there will have the answer for me...! I'll start with what I have, then I'll continue to the problem itself.
3
1581
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but they're just as new to ASP.NET as I am. Is it possible to have a dataset filled with all the records in an SQL table (on the small side, maybe three hundred records total), and then query that table for subsets of data, e.q. a simple WHERE clause,...
4
1590
by: paulb | last post by:
I was wondering if it is possible to continuously query a real-time datastream using SQL Server. Does anyone have any experience of this? I have found LINUX based systems such as Borealis and STREAM. I would prefer to use a Windows based system as the program using the query results is Windows based.
5
3689
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an XML file. Once my application starts, I load this XML file into a DataSet object using "ReadXML" function. This creates a dataset in memory with 6 tables.
3
4038
by: RJN | last post by:
Hi I've written a code that queries Windows LDAP server and works fine, but the same doesn't work when querying Solaris LDAP server. DirectoryEntry de = new DirectoryEntry("LDAP://server.com"); DirectorySearcher ds = new DirectorySearcher(de); de.Username = "xxx"; de.Password = "yyy"; de.AuthenticationType = AuthenticationTypes.Secure;
2
1742
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding : Querying the database everytime for next 100 records ( that means i need to set up a cursor) till the count of the table rows ends up(take 1 million rows e.g.) The database is DB2
2
1784
by: iheartvba | last post by:
Hi, I usually use access query builder to create complex queries. Especially to create Sub Queries I.E. a querying another query. In my current situation I need to provide the criteria to the query from a Form and then call it using the rst function in ADO (see last line of my code). The issue with the rst function is that it doesn't cater for queries made in access query builder that have an object from a Form as their criteria. I have...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10532
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10302
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10058
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7597
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.