473,785 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining two select queries into one ?!?

Lo group,

I am wondering if there is a way of combining two SELECT statements into
a single query.

Here's the obligatory example to clarify things:
SELECT id WHERE name=mike
SELECT bills WHERE nameid=12 (12 being the result of the first query)

Right now I am executing two separate calls and I would ofcourse like to
bring that down to a single call.

Any help or pointers would be more than appreciated,

SomeDude.

Oct 8 '05 #1
2 2111
SomeDude wrote:
SELECT id WHERE name=mike
This query won't work. Table name is missing from it and value is not
inside '' characters.
SELECT bills WHERE nameid=12 (12 being the result of the first query)


This also is missing the table name.
But perhaps something like this:

select useraccount.id, bill.* from useraccount where name='mike'
left join bill on useraccount.id= bill.nameid;
Please note that the query might not be usable just like that. It
depends on what kind of results you wish to get and since you didn't
even provide working example, it is impossible to tell what you really
expect to get.
Oct 8 '05 #2
On Sat, 08 Oct 2005 17:53:40 +0000, Aggro wrote:
SomeDude wrote:
[quoted text muted]


This query won't work. Table name is missing from it and value is not
inside '' characters.
[quoted text muted]


This also is missing the table name.
But perhaps something like this:

select useraccount.id, bill.* from useraccount where name='mike'
left join bill on useraccount.id= bill.nameid;
Please note that the query might not be usable just like that. It
depends on what kind of results you wish to get and since you didn't
even provide working example, it is impossible to tell what you really
expect to get.

Thanks for pointing to LEFT JOIN Aggro, I'll dive into it.

SomeDude

ps: the example was simplified on purpose ;)

Oct 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2798
by: frizzle | last post by:
Hi, I know this might sound strange but i think(/hope) it's quite simple: I'm running 2 queries in a mysql DB, first one returns 20 results. Now how can i echo results from the second query in the 1st query's result, like:
1
6016
by: Bruce MacDonald | last post by:
I've got a question/request for the SQL gurus. I'm building a model of bandwidth demand in MS Access and want to get aggregated results for demand at each PCP in each time period. The two queries below are used to count the number of households of each Socio-Economic Type (each postcode has been allocated an SE-Type), and use that to count the number of connections requiring a bandwidth less than 512 that will be required at the PCP in...
2
2363
by: Mark Harrison | last post by:
How can I combine these two queries? # select viewerid,count(*) from viewer_movies group by viewerid order by viewerid; viewerid | count ----------+-------- 22964835 | 3055 22964836 | 1291 22964837 | 3105 22964838 | 199
1
2068
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
7
2234
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !! Essentially, I want to get the same column out of the single table, but in one case the column must have a where clause associated with it, and the other case it does not have a where clause... Lets say have a table like this :-
1
2285
Altius
by: Altius | last post by:
Access Version: 2003 OS: XP Pro Sorry if this is a bit long winded. First a little info about the database. This database is used to keep track of checkout information from our production department. It has three main tables that store information, the first one, that I have named "Checkout", stores the information I am querying for the two reports. It has six different fields - OrderNumber, Date, CheckedBy, BuiltBy, SerialNumber, and...
2
1708
by: spatik | last post by:
I have a scenario like this in my application. We can have values documented for each time column. I have discrete timepoints in hand and I need to find the documented values just before and just after the time columns. Consider a scenario where I have 8 time points like 10:00,10:05,10:10,10:15,10:20,10:25,10:30 and 10:35. I run a query for that like to find the documented value just before the 8 time points. I also run the same big...
3
1556
by: billelev | last post by:
I am trying to combine two queries into one UNION query. The first sub-query works, but the second creates the following error at the end of the first iif statement: "Syntax error in union query" Does anybody know why? Select Symbol, MarketValue AS , Type, RiskType FROM . AS tmpVarPositions UNION SELECT Symbol, Sum(MarketValue), AlteredType as Type, RiskType
3
2844
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
0
9480
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
10324
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
10147
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...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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...
1
4050
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.