473,387 Members | 1,569 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.

How to merge output from two select statements?

Can anyone help here? I'm stuck at a step in this process, and I'm a little fried from staring at the comp for 8 hours already on this one thing...

the two selects below need to be returned as a single table. Can I Concat? Union? Join?

Can I somehow join the results of the select statements?

and anywhere you see "4" will be a user variable.




Expand|Select|Wrap|Line Numbers
  1.  
  2. select d.dname Department, e.fname First, e.lname Last
  3.        from department as d, employee as e
  4.        where d.mgrssn = e.ssn AND d.dnumber=4;
  5.  
  6. select count(distinct(e.ssn)) Number_of_Employees,
  7.        count(distinct(works_on.pno)) Number_Of_Projects_Under_Dept,
  8.        Sum(works_on.hours) Hours_Worked
  9.        FROM employee AS e, (works_on JOIN project ON works_on.pno=project.pnumber)
  10.        WHERE project.dnum=4 AND e.dno=4 AND e.ssn=works_on.essn;
  11.  
Nov 8 '10 #1
1 2227
omerbutt
638 512MB
yes you can if you have some kind of key that is saved in both the tables and is unique

table_A name ,age, email, user_id
table_B picture ,website , contact info, user_id
Expand|Select|Wrap|Line Numbers
  1. $Q="select * from 
  2.    table_A as a, 
  3.    table_B as b
  4. where 
  5.    a.user_id=b.user_id ";
  6.  
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.   if(mysql_num_rows(RESULT_SET)){
  3.     while($f=mysql_fetch_array(RESULT_SET)){
  4.       echo $f['name'].$f['Picture'];
  5.     }
  6.   }
  7. ?>
  8.  
Nov 12 '10 #2

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

Similar topics

2
by: james14 | last post by:
I need to run a stored procedure on all the results of a select query. For a simplified example, I'd like to be able to do something like this: SELECT JobID, QtyToAdd FROM Jobs WHERE...
1
by: Thilo-Alexander Ginkel | last post by:
Hello, I am currently trying to assign some string to a TEXT output parameter of a stored procedure. The basic structure of the stored procedure looks like this: -- 8< -- CREATE PROCEDURE...
1
by: TRiaRii | last post by:
Hi My problem is a visual basic select what I like migrate to a stored procedure, by example: str="select * from t1 where" str=str & IIf(a=0, t1.a>0 and t2.b<0, t1.a<0) & "and " & IIf(c=0,...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
1
by: stjulian | last post by:
If inside a stored procedure, there a SELECT statement to return a recordset and another SELECT to set the value of an output parameter (as in SELECT @OutValue = Name FROM table WHERE pkid=5),...
3
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
6
by: HJ | last post by:
Hi all, I am experiencing a weird issue and I hope you can help. We are using a Microsoft Access 2003 project (.ade) with an SQL Server 2000 database. One form contains a list box with the...
2
by: DotNetDanjo | last post by:
I want a stored procedure to run a select query on it's own like this: Select *, user_id As UserId FROM CC_host.dbo.usr_table Where(email LIKE N'%@%usa.com') But from these results I want the...
8
by: yrrah | last post by:
Hello, i've a problem regarding the select stmt inside the stored procedure. Here's my code: DELIMITER $$ DROP PROCEDURE IF EXISTS `p`.`getNames`$$ CREATE PROCEDURE `p`.`getNames`(q...
0
by: Geethu03 | last post by:
Hi I had a doubt in Mysql Stored procedure. i need to read a text file (that is stored in mysql database) using the Stored procedure. i know little bit about the Stored procedure but i am not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.