www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help comparing tables

  1. #1
    Join Date
    Mar 2011
    Posts
    79

    Help comparing tables

    Hey guys I created a site that host contest. I need to compare which contest my users have not applied to and display them using pagination.

    I have to tables joined_contest which hold a list of contest my users apply to and available_contest which hold the list of contest available.

    I need a query that can compare the contest my user has already joined and the contest they have not joined yet.

    my example :
    [block]$query="Select available_contest.title FROM available_contest INNER JOIN joined_contest ON available_contest.title != joined_contest.title WHERE available_contest.status='ON'";[/block]

    +++The query above only gets me about 2 contest :
    1. Basically I'm asking(trying) to compare available_contest to joined_contest
    and get the contest that my user has not joined.

    Again I need a query that will compare one table1 to table2 and pull from table1 that is not in table two.
    My pagination will use this same query to output the results, thanks.

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    This the kind of thing you're looking for?

    Code:
    select title from `available_contest` where status - 'ON' and title not in (select title from `joined_contest` where userid = 'x')
    PS: Joins have always boggled my mind and I've never put any real effort into figuring them out - subqueries are easier to read for me.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles