473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2078
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
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...
1
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...
2
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 | ...
1
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...
7
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 !!...
1
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...
2
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...
3
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" ...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.