Hi there, first request for help, an a newbee so be gentle with me !
I have :
Two tables
products & categories
products table -
productID
productcategoryID
productname
categories table -
categoryID
name
parentID
I want a query which selects each product shows it's name, it's product ID, it's product category (by name) and it's product category parent (by name). My problem is that within categories the parentID can be the categoryID and I'm not sure how to construct the Query
Example data
productID - 1001
productcategoryID - 120
productname - "200gb Hard Disk"
productID - 1002
productcategoryID - 110
productname - "R/W CD Drive"
categoryID - 100
name - Drives
parentID - Null
categoryID - 110
name - CD Drives
parentID - 100
categoryID - 120
name - Hard Disk Drives
parentID - 100
The output I would like is
1001 200gb Hard Disk Hard Disk Drives Drives
1002 R/W C/D Drive CD Drives Drives
I would appreciate your assistance
Kind Regards
Darrin
2 1535
try this: -
SELECT
-
p.productID as ProductID,
-
p.productname as ProductName,
-
c.name as ProductCategory,
-
pc.name as ParentProductCategory
-
FROM products p
-
LEFT JOIN categories c on p.productcategoryID = c.categoryID
-
LEFT JOIN categories pc on c.parentId = pc.categoryID
-
Hiya
Thanks for responding to my question about an SQL Select statement, unfortunately I wasn't specific about the actual table and field names that I am using and I am having trouble transposing the instruction you left into my DB. I have listed below the actual table names and fields, could you be kidn enough to resubmit detals using the table/field names I have shown below
Many thanks
Darrin
TABLE - ss_categories
Fields - categoryID, name, parent
TABLE ss_products
Fields - productID, categoryID, description, name, price, in_stock
I want to be able to SELECT product information (name, description etc) and show it's category name and that categories parent as well
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James |
last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39
I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did
not work. I also had an abortive download from PHP.NET as...
|
by: sah |
last post by:
I need some help with the following query:
DECLARE @SRV VARCHAR(20), @date smalldatetime
SET @SRV = (select @@servername)
SET @date = '20040901'
select Srv_Name = @SRV, DB_Name = 'DB_NAME',...
|
by: Martin Hampl |
last post by:
Hi,
I am using PostgreSQL 7.4, but I did have the same problem with the
last version.
I indexed the column word (defined as varchar(64)) using lower(word).
If I use the following query,...
|
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...
|
by: John Baker |
last post by:
Hi:
As those who have looked at this newsgroup recently will realize, I am a neophyte with
Access, although I have experienced with Approach (the Lotus product). There are things I
could easily...
|
by: hope |
last post by:
Hi
Access 97
I'm lost on this code please can you help
=================================
Below is some simple code that will concatenate a single field's value from multiple records into a...
|
by: Rated R1 |
last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got
and see if someone can please help me. Email me and we can set something up as
Id even be willing to pay for your...
|
by: David |
last post by:
Hi,
I cannot get the following (MS Access) SQL statement working in my asp
page, please can anyone help me ? Thanks :-)
------------------------------------------------
<%
strQuery =...
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the...
|
by: uno7031 |
last post by:
Help Please!!! Adding 5 Days to another Date in an access query
Good Morning,
Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |