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

Subquery Help

Here's my setup. I have three tables I am working with: product,
attribute, and vendor. An attribute is a variation of a product. For
instance, if I have a widget, a red widget would be one attribute, a green
widget would be a second, a blue one would be a third, and so on. A product
is identified by a nine digit SKU, and an attribute is identified by an 11
digit SKU. The attribute SKU is the product SKU plus a two digit
identifier. for instance, if the product SKU is 123456789, the first
attribute would be 12345678901, the second would be 12345678902, and so on.

The vendor table contains all vendors, and they can be either a manufacturer
or a distributor. Each vendor is identified by a vendor_id value. Each
product has a manufacturer and a distributor, idientified by the
product.manufacturer_id and product.distributor_id fields, where those two
fields contain a vendor_id.

I need to generate a report that lists all attributes for a given vendor
(the vendor is chosen from a drop down list in an HTML form). I am trying
to write a query that will get this data instead of having to do multiple
queries. I was going to use a subquery, but the version of MySQL on the
ISP's server is 4.0.22, so subqueries aren't supported (only after 4.1
according to the MySQL site).

So it looks like I need to go through two steps to get the data I need:
1) Get all records from the product table that have a certain
manufacturer_id value
2) For each product, get all corresponding rows in the attribute table.

With 4.0.22, is it possible to get this data in one query? Or do I need to
do something like:
1) Run first query to get list of products with appropriate manufacturer_id
2) Put each value in an array
3) For each product_sku, get the corresponding rows from the attribute table

Or is there a third option I should consider?

Thanks.

Steve
Jul 17 '05 #1
2 1340
On 2005-05-03, Steve Edwards <ra***********@hotmail.com> wrote:
I need to generate a report that lists all attributes for a given vendor
(the vendor is chosen from a drop down list in an HTML form). I am trying
to write a query that will get this data instead of having to do multiple
queries. I was going to use a subquery, but the version of MySQL on the
ISP's server is 4.0.22, so subqueries aren't supported (only after 4.1
according to the MySQL site).
Could you give us an example of that query then?
Or is there a third option I should consider?


Read a SQL manual, and pay special attention to the JOIN clause.

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
Steve Edwards wrote:
widget would be a second, a blue one would be a third, and so on. A
product is identified by a nine digit SKU, and an attribute is identified
by an 11
digit SKU. The attribute SKU is the product SKU plus a two digit
identifier. for instance, if the product SKU is 123456789, the first
attribute would be 12345678901, the second would be 12345678902, and so
on.
<snip> Or is there a third option I should consider?


Normalize your data - the composite key in the attribute relation breaks
first normal form.

C.
Jul 17 '05 #3

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

Similar topics

0
by: leegold2 | last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in the subquery below because of the subquery's error message. I thought w/"IN" I'd get three (3) records returned as expected....
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
6
by: phillip.s.powell | last post by:
update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);...
2
by: reap76 | last post by:
I am running the following query: if (select IntExternalAccountID from ExternalAccount) = (select IntExternalAccountID from InternalAccount) select * from InternalAccount where AccountPurpose=2 ...
0
by: fubaba | last post by:
hi, i execute a store procedure got Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'...
13
by: ThePrinceIsRight | last post by:
I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query....
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
3
by: jideesh | last post by:
---------------trigger code create trigger DeletepurchaseItems on table_purchaseitems for delete,update as begin select * from deleted update table_STOCK set ostock=(ostock-(select sqty from...
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: 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:
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
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
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?
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
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
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.