473,396 Members | 1,814 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,396 software developers and data experts.

how do i do Join two query

rajiv07
141 100+
Hi to All

I want to join these two queries into one.


[PHP]my $cStr="select sum(cart.rate),cart.currency,trackinfo.title,count (cart.cartid) from trackinfo,cart where cart.trackid=trackinfo.trackid and cart.currency=\'INR\' group by trackinfo.title order by trackinfo.title";[/PHP]

[PHP]my $cStr1="select sum(cart.rate),cart.currency,trackinfo.title,count (cart.cartid) from trackinfo,cart where cart.trackid=trackinfo.trackid and cart.currency=\'USD\' group by trackinfo.title order by trackinfo.title";[/PHP]


Here the currency value olny differ from two quires.so i want to join these queries into one. Is any Idea please.

Thanks In advance .
Aug 21 '07 #1
5 4829
ak1dnar
1,584 Expert 1GB
Join for what purpose?
Based on what condition you want to get your result?

For now your Where Clause:

Expand|Select|Wrap|Line Numbers
  1.  where 
  2. cart.trackid=trackinfo.trackid 
  3. and 
  4. cart.currency='INR'
  5. and 
Do you prefer to put the another Condition Here
Aug 21 '07 #2
rajiv07
141 100+
Thank u ajaxrand

Let me Explain clearly

trackinfo table
Expand|Select|Wrap|Line Numbers
  1. +---------+---------+
  2.  trackid |     title 
  3. +---------+---------+
  4.        1 |   aa   
  5.        2 |   bb    
  6.  

cart table
Expand|Select|Wrap|Line Numbers
  1. +--------+---------+----------+------+
  2. | cartid | trackid | currency | rate |
  3. +--------+---------+----------+------+
  4. |      1 |       1  | INR       |  500 |
  5. |      2 |       2  | INR       |  500 |
  6. |      3 |       1  | INR       |  500 |
  7.        4 |       2 |  USD     |  100 |  
My Out what i am Expecting
Expand|Select|Wrap|Line Numbers
  1. ----------------------------------------------------
  2. track-title | sum(cart-rate) | currency|
  3. -----------------------------------------------------
  4. aa           |           1000    |      INR
  5. bb           |            500    |      INR
  6. bb           |           100     |      USD
  7. ----------------------------------------------------
The result should group with trackinfo.tile and cart.currency;

Is Any idea please.

Thank u.
Aug 21 '07 #3
ak1dnar
1,584 Expert 1GB
Just Check whether this is correct or not;

Expand|Select|Wrap|Line Numbers
  1. select trackinfo.title as TrackTitle ,sum(cart.rate)as Rate,cart.currency from trackinfo 
  2. Left Join cart on trackinfo.trackid=cart.trackid 
  3. Where cart.currency = 'INR' or cart.currency = 'USD'
  4. group by trackinfo.title,cart.Currency
Aug 21 '07 #4
rajiv07
141 100+
It's working.Thank u for your such a brilliant Reply.Thank u so much.
Aug 21 '07 #5
ak1dnar
1,584 Expert 1GB
It's working.Thank u for your such a brilliant Reply.Thank u so much.
Glad to hear that. post back anytime to the Forum. Good Luck!
Aug 21 '07 #6

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
5
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run...
14
by: Jim Andersen | last post by:
I have a problem with this standard employee-supervisor scenario For pictures: http://www.databasedev.co.uk/self-join_query.html I want to show all employees "belonging" to a specific...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
0
by: mlarson | last post by:
I have a program that worked fine then they needed to be able to also see the empty cells (inmate cells) on a housing unit when they ran the query. So what I had to do was take two tables and...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
3
by: nico3334 | last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using LEFT OUTER JOIN. Here is an example of that query: SELECT a.supply, a.state, b.cost FROM Table1 a LEFT...
2
theGeek
by: theGeek | last post by:
I always wonder which one of join or subquery should I be using to solve a particuar problem so that I get the correct result set in minimum time. It usually happens that I can write a query quickly...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...

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.