Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:54:31+00:00 2026-05-25T22:54:31+00:00

I have 2 tables colorcode & users colorcode ID colorid colorname ———————— 1 1

  • 0

I have 2 tables colorcode & users

colorcode

ID colorid  colorname
------------------------
1  1        yellow
2  2        black
3  3        red
4  4        white

users

ID userid  colorid
------------------------
1  1        1,2
2  2        3,4
3  3        1,3,4
4  4        1

How do I retrieve & query individual colorid

$aa = $db->query("SELECT * FROM colorcode"); 
$colors = array();
   while ($colordata = mysql_fetch_assoc($aa)) {
   $colors[] = $colordata["colorid"];
}

Let’s say I want query which users have yellow color & what it’s the statement should I use for users

SELECT .. FROM users
WHERE colorid ....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:54:32+00:00Added an answer on May 25, 2026 at 10:54 pm
    SELECT * FROM users
    WHERE colorid LIKE "%1%"
    

    But what I would really do is make a link table from users to colors:

    usersToColors:

    ID userid  colorid
    ------------------------
    1  1        1
    2  1        2
    3  2        3
    4  2        4
    ...
    

    Then you could do:

    SELECT * FROM users u, usersToColors utc
    WHERE u.userid = utc.userid 
          AND utc.colorid = 1;
    

    Or even:

    SELECT * FROM users u, usersToColors utc, colors c
    WHERE u.userid = utc.userid 
          AND utc.colorid = c.colorid
          AND c.colorname = "yellow";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables: Table: Color Columns: Id, ColorName, ColorCode Table: Shape
I have tables: users with the fields id, premium votes with the fields userid,
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have tables linked by FK, I query on the first table using entity
I have tables like: 'profile_values' userID | fid | value -------+---------+------- 1 | 3
I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via
I have tables & data like this: venues table contains : id +----+---------+ |
I have tables contracts and users and i need to show contracts sorted by
I have tables like this COUNT tbl id, userid, linkid, count 4 1 6
What causes a query of joined tables to display duplicate data. I have tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.