473,804 Members | 4,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

aligning multiple query results

I'm trying to pull data from 2 different tables and do a loop to
retrieve more than one row. I'm having problems with aligning the
information. Can someone lead me in the right direction? I've done some
looking myself and found something called GROUP BY? Is that what I need
to use? Thanks in advance.

Jan 7 '06 #1
28 2251
kiqyou_vf wrote:
I'm trying to pull data from 2 different tables and do a loop to
retrieve more than one row. I'm having problems with aligning the
information. Can someone lead me in the right direction? I've done some
looking myself and found something called GROUP BY? Is that what I need
to use? Thanks in advance.


Sorry, my mind reading isn't working this morning.

It's impossible to tell without knowing the structure of your tables,
the code you're using and the output you expect.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jan 7 '06 #2
Jerry Stuckle wrote:
kiqyou_vf wrote:
I'm trying to pull data from 2 different tables and do a loop to
retrieve more than one row. I'm having problems with aligning the
information. Can someone lead me in the right direction? I've done some
looking myself and found something called GROUP BY? Is that what I need
to use? Thanks in advance.


Sorry, my mind reading isn't working this morning.

It's impossible to tell without knowing the structure of your tables,
the code you're using and the output you expect.

Sounds more like a UNION problem, but Jerry is right. We need more
information to make reasonable comments.

-david-

Jan 7 '06 #3
I have a page that displays multiple search results. On each search
result I want unique information from two or more tables to be
displayed. All tables have a "client_id" column. I need the main query
to display results based on the $_GET['keywords'] and a second table to
display results based on the "client_id" of the main query. I don't
have any code as of yet to show you. I have done some research on UNION
and found this on mysql.com:

"Selected columns listed in corresponding positions of each SELECT
statement should have the same type. (For example, the first column
selected by the first statement should have the same type as the first
column selected by the other statements.) The column names used in the
first SELECT statement are used as the column names for the results
returned."

Is this going to be a problem since the names and information are going
to be different on each of my tables.

Jan 9 '06 #4
kiqyou_vf wrote:
I have a page that displays multiple search results. On each search
result I want unique information from two or more tables to be
displayed. All tables have a "client_id" column. I need the main query
to display results based on the $_GET['keywords'] and a second table to
display results based on the "client_id" of the main query. I don't
have any code as of yet to show you. I have done some research on UNION
and found this on mysql.com:

"Selected columns listed in corresponding positions of each SELECT
statement should have the same type. (For example, the first column
selected by the first statement should have the same type as the first
column selected by the other statements.) The column names used in the
first SELECT statement are used as the column names for the results
returned."

Is this going to be a problem since the names and information are going
to be different on each of my tables.

It sounds more like you want an inner join not a union (unless the
tables are from different data sources). It's hard to advise without
some concrete details, but it *sounds* like you have a table 'a' with a
client_id and some other values and a table 'b' with a client_id and
some other values and you want to show values from a and b.

So, the select would be something like:
select
a.column1,
a.column4,
b.column7
from
a,
b
where
a.client_id = b.client_id <-- inner join
and (any other conditions)

-david-

Jan 9 '06 #5
I have a page that displays search results. With each entry returned, I
want to be able to display rows from 2 or more tables.

table.qcbd has a keywords column that I want to search and
table.qcbd_home has a description that I want to include in the search
results. So if a search for "cups" returned 8 results, I would want
each result to have information from table.qcbd AND table.qcbd_home .
I'm not exactly sure how to go about doing this. I've tried some really
messy coding, putting a query INSIDE of the while loop, lol- that
didn't work.

This is not the code, but I'll describe what I want to do like this:
SELECT * FROM qcbd, qcbd_ghours WHERE keywords = $_GET['search']

I would then do a loop and extract all of the returned rows from both
tables. The problem I'm running into is that the returned rows dont
line up.

Hope this clears things up. As for the code, I don't really have
anything of use to show you. Thanks!

Jan 9 '06 #6
kiqyou_vf wrote:
I have a page that displays search results. With each entry returned, I
want to be able to display rows from 2 or more tables.

table.qcbd has a keywords column that I want to search and
table.qcbd_home has a description that I want to include in the search
results. So if a search for "cups" returned 8 results, I would want
each result to have information from table.qcbd AND table.qcbd_home .
I'm not exactly sure how to go about doing this. I've tried some really
messy coding, putting a query INSIDE of the while loop, lol- that
didn't work.

This is not the code, but I'll describe what I want to do like this:
SELECT * FROM qcbd, qcbd_ghours WHERE keywords = $_GET['search']

I would then do a loop and extract all of the returned rows from both
tables. The problem I'm running into is that the returned rows dont
line up.

Hope this clears things up. As for the code, I don't really have
anything of use to show you. Thanks!

Do table.qcbd and table.qcbd_home have a column of data that is a)
unique row in each table and b) defines some relationship between the
two tables? If so, you need to join the two tables based upon that
column. If not, the two tables are probably going to be joined with a
sub-select.

To join two tables you need to have an element in common to join them
on. The result may be one or more rows depending upon the nature of the
data in the joining columns.

It sounds like you want something like:

select qcdb_hours
from gcdb_home
where ??? in (
select ????
from qcdb
where keywords = '$_GET['search']'
)

At any rate, this seems to be more of a SQL problem rather than a PHP
problem. I would suggest you move your query over to one of the mysql
news groups.

-david-

Jan 9 '06 #7
I have a page that displays multiple search results. On each search
result I want unique information from two or more tables to be
displayed. All tables have a "client_id" column. I need the main query
to display results based on the $_GET['keywords'] and a second table to
display results based on the "client_id" of the main query. I don't
have any code as of yet to show you. I have done some research on UNION
and found this on mysql.com:

"Selected columns listed in corresponding positions of each SELECT
statement should have the same type. (For example, the first column
selected by the first statement should have the same type as the first
column selected by the other statements.) The column names used in the
first SELECT statement are used as the column names for the results
returned."

Is this going to be a problem since the names and information are going
to be different on each of my tables.

Jan 9 '06 #8
Hey, thanks a lot for pointing me in the right direction. I'll head on
over to a mysql group. Sorry about multiple posts, Google has been
acting up for me. THANKS!

Jan 9 '06 #9
I have a page that displays multiple search results. On each search
result I want unique information from two or more tables to be
displayed. All tables have a "client_id" column. I need the main query
to display results based on the $_GET['keywords'] and a second table to
display results based on the "client_id" of the main query. I don't
have any code as of yet to show you. I have done some research on UNION
and found this on mysql.com:

"Selected columns listed in corresponding positions of each SELECT
statement should have the same type. (For example, the first column
selected by the first statement should have the same type as the first
column selected by the other statements.) The column names used in the
first SELECT statement are used as the column names for the results
returned."

Is this going to be a problem since the names and information are going
to be different on each of my tables.

Jan 9 '06 #10

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

Similar topics

7
6220
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
4
16760
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from customers; I can execute each statement individually but get the 'you have an error in
3
7757
by: Gord | last post by:
I would like to create a summary report from the results of 11 queries (based on 2 tables). All the queries have the same format and return 3 numbers (Count, Current Year Bal, Last Year Bal.) under different conditions. When I use the Report Wizard to select multiple queries to be included in my report, I got an error msg. It says "You have chosen fields from record sources which the wizard can't connect. You may have chosen fields...
2
15071
by: Scott Cannon | last post by:
I am trying to query 3 tables all related by Clinet_ID. The Clients table, Monthly_Expenses table and Monthly_Income table. Each client can have 0>M instances of expenses, past due expenses, and income so I am using the SUM aggregate function to get the totals for the Monthly_Epenses.Amount, Monthly_Expenses.Past_Due_Amount, and Monthly_Income.Amount. Then problem I am having and cannot seem to resolve is that the Monthly_Income is...
5
5673
by: Beacher | last post by:
I've noticed that you can only have a sub datasheet pointing to one table... is there anyway to change this? for example I have Customer | ---------- Customer/Product | ----------- Customer Grp/Sales Grp
1
1543
by: kiqyou_vf | last post by:
Sorry, Google wouldn't let me post a reply. Here is the convo thus far: Jerry Stuckle wrote: > kiqyou_vf wrote: >> I'm trying to pull data from 2 different tables and do a loop to >> retrieve more than one row. I'm having problems with aligning the >> information. Can someone lead me in the right direction? I've done some >> looking myself and found something called GROUP BY? Is that what I need >> to use? Thanks in advance.
1
2852
by: Barb.Richards | last post by:
I have created an append query that pulls information from one database, and will append the selected information into a new table. The fields are setup like 'number' 'category' 'code' 'shares' and 'dollars'. Using the "backend" of this table I can filter the numbers by right clicking and using Filter For: then enter 1 or 2 or 3 and this will return results for all information that has 1 or 2 or 3 as a number. However, the problem I...
1
6290
by: tjm0713 | last post by:
Not sure this can be done but here is my current situation. I have a table containing millions of records. Each record has 28 fields. One of the fields I am trying to return the single record for is Res_code. There can be multiple records with the same Res_code. Some of the matching Res_code records can have different values in any of the 28 fields and some may have exactly the same value in each field. Example: Res_Id ...
0
9710
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
9589
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
10593
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
10340
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
10085
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
7626
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
5527
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
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
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.