Extracting unique values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yasmine
    New Member
    • Feb 2008
    • 64

    #1

    Extracting unique values

    Hi friends,

    Can anyone tell me how can i write a php script which extract all the unique values of a field from multiple tables?
    and also if anybody enters some new values it also should be stored in the unique table.

    That is exactly what i meant is that
    consider different category of courses offered and stored in different tables. Now, i need to extract all the unique courses with its id and keep it in a separate table. I know this should be done by 'group by' clause. Is it right?

    What i'm asking is if anybody creates a new course how that should be stored in my new table? also this script should be run everyday from when i log on to my system to log off.


    Thanx n regards
    Yas
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Yas,

    Before you read on please realise that I am making some assumptions and applying some guess work about your exact system situation.

    It seems to me that you have an interesting way of handling what should be a simple problem. You mentioned in your post that you want to keep a list of unique courses. So every time someone says they are on a course you would need to check if that course is in the unique list and if not add it to the list.

    I cannot see the point of this unique table in this scenario. You can find out the number of unique values with a group by or a SELECT DISTINCT.

    However, the approach you outline is interesting. By intersting I mean that in my opinion you are tackling the issue the wrong way round.

    I would create a table that is going to store these unique course titles. This can be updated by people as a separate process, perhaps only users with certain priveleges on the system can do this. This table with it's unique ID can be used as a lookup point for the tables where courses are listed against other items(people maybe).

    2 tables (excuse the mass assumptions)
    1 - tbl_courses
    ID
    course_name

    2 - tbl_students
    ID
    student_name
    course_ID

    When adding a student select the course from a list box ad add the ID to tbl_student. This is the solution I would implement. If 1 student can be on many courses then a third table in between students and courses is needed.

    this is the approach I would take, but now my lunch is ready, so TTFN.

    Cheers
    nathj

    Comment

    Working...