SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard mcsolas's Avatar
    Join Date
    Jul 2004
    Location
    Hermosa Costa Rica
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select for 2 tables - how to get all records.

    I am asking for a list of records, here from my Consumer table. These people also have usernames stored in another table Users. I point back to these by the 2 AND statements below. This works great, the query below correctly pulls 4 records back that do have usernames. However, I am trying to build a list of ALL consumers, then display the Users.UserName field IF it exists there. So in other words, this query needs to be returning me 1000 records and displaying 4 of those with usernames.

    I am sure its my sql logic here .. im getting better but its a long road
    SELECT *
    FROM Consumer,Users
    WHERE 0 = 0
    AND Users.UserTableID = Consumer.ConsumerID
    AND Users.UserTable = 'Consumer'
    ORDER BY ConsumerID ASC

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    700
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT *
    FROM Consumer left join Users 
    on Users.UserTableID = Consumer.ConsumerID
    AND Users.UserTable = 'Consumer'
    ORDER BY ConsumerID ASC

  3. #3
    SitePoint Wizard mcsolas's Avatar
    Join Date
    Jul 2004
    Location
    Hermosa Costa Rica
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I can apply this to several pages which needed this fix.


Bookmarks

Posting Permissions

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