Forums

This topic is locked

How do i get DISTINCT info from 2 tables

Posted 24 Jan 2007 22:32:27
1
has voted
24 Jan 2007 22:32:27 rob hewitt posted:
Q. i have two tables - 'stylesa' (for adult dance styles) & 'stylesc' (for childrens dance styles), both just have one field - style. i have 2 drop down boxes populated with records from each table.

i'm trying to populate 1 drop down box with details from both tables, selecting distinct records -excluding duplicates.

i'm at a lost to figure out the SQL for this, not sure if its a UNION, JOIN, multiple SELECT etc.

I'm using MySQL 5.021 with DMX 8.02.

Any ideas ?

Replies

Replied 25 Jan 2007 01:14:39
25 Jan 2007 01:14:39 rob hewitt replied:
ive come up with the following but am not sure if it is correct :

SELECT DISTINCT stylesc.style FROM stylesc, stylesa where stylesc.style <> stylesa.style and order by style ASC
Replied 26 Jan 2007 20:04:47
26 Jan 2007 20:04:47 Alan C replied:
This is not really my speciality, but on a system I am developing I had a need for dropdown selection boxes and after a lot of consideration, procrastination etc decided that each would go into a separate table.

That was the best decision ever becase as soon as I started testing I realised that I needed more options in the selects, so all I needed to do was insert a couple more lines into the appropriate table and the job was done.

So . . . I suggest separate tables for adult and child sytels, then make dynamic dropdowns from each.

BTW if you have more than one value so you are having to do a distinct select that suggests that you are perhpas storing redundant data, if you put the styles into a separate table you could then store the id from that second table as a foreign key in the first table, that way your style information only gets stored once.

Reply to this topic