Jason Caldwell wrote:
Hi
I have two tables; tbl_Headers and tbl_SubItems.


tbl_Headers contain my Header Items such as (fields: ID & HEADER)

ID     HEADER
-------------------
1.00   TOPIC ONE
2.00   TOPIC TWO
3.00   TOPIC THREE

tbl_SubItems contain Sub Header Items such as (fields: ID & SUBITEM)

ID     SUBITEM
-------------------
1.01   SubItem 1
1.02   SubItem 2
1.03   SubItem 3
2.01   SubItem 1
2.02   SubItem 2
3.01   SubItem 1
3.02   SubItem 2

etc and so on ...

I want to output a list like so:

1.00 TOPIC ONE
1.01 SubItem 1
1.02 SubItem 2
1.03 SubItem 3
2.00 TOPIC TWO
2.01 SubItem 1
2.02 SubItem 2
3.00 TOPIC THREE
3.01 SubItem 1
3.02 SubItem 2

etc and so on ...

I'm brain-cramping on this, can someone please help ?

If you use version 4.x of mysql you could use a UNION:

(SELECT * FROM tbl_Headers)
  UNION
(SELECT * FROM tbl_SubItems)
  ORDER BY ID;

<URL: http://dev.mysql.com/doc/mysql/en/UNION.html >

If you use mysql version 3.x: It would be easy if all items was in the same table, then you could just order by ID... A temporary table can help, try something like this:

CREATE TEMPORARY TABLE tmp1
  SELECT ID,HEADER as ITEM FROM tbl_Headers;
INSERT INTO tmp1 SELECT ID, SUBITEM as ITEM FROM tbl_SubItems;
SELECT * FROM tmp1 ORDER BY ID;

--
Roger


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to