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 8420473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:53:35+00:00 2026-06-10T02:53:35+00:00

Here is the case: There is a user table id email orders_counter ================================= 1

  • 0

Here is the case:

There is a user table

id     email      orders_counter
=================================
1      a@a.com    5
2      b@b.com    3
3      c@c.com    0

And a user data table for user’s other data

id     user_id      title      value
=======================================
1      1            Name       Peter Johnson
2      1            Tel        31546988
3      2            Name       Alan Johnson
4      2            Tel        56984887

If I want to fetch all user that

1, orders_counter greater then 3
2, Name contain 'Johnson'
3, Tel contain '88'

AT THE SAME TIME

What is my sql, and if I want to do it rubyonrails way
what is the ActiveRecord code
I know I can it one by one and then join all of them together, but it waste too much resource while conditions build up

  • 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-06-10T02:53:36+00:00Added an answer on June 10, 2026 at 2:53 am
    Select * From `user` u
    inner join `userdata` d on d.user_id=u.id and d.title='Name' and d.value like '%Johnson%'
    inner join `userdata` c on c.user_id=u.id and c.title='Tel' and c.value like '%88%'
    where orders_counter > 3
    

    the way that you’ve got your user data table structured, you’ll almost always have to join on that table several times in order to “pivot” those values into columns. I’d recommend just creating a table that has name and tel as columns. then the query becomes a lot more simple

    select * from `user` u
    inner join `user_data` d on d.Tel like '%88%' and d.Name like '%johnson%'
    where u.orders_counter > 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just going to throw all my code in here in case there's something
Here is the case. User should be able to open MS Word document which
Here's the use case: A user clicks on a link that opens a window
Here's my use case : public class User extends Model {} public class TableA
I have a table in my database to store user data. I found a
Table User contains the fields id, name, fruit, veggies, meat. Table FruitType contains the
I have five tables: User user_id | name -------------------- 0 | Mark 1 |
Would there be any benefit in using JSON to store data in a table
I have a logging table that stores the user id, date/time, table name, record
For example (in my case) here's some code, <?php woo_post_inside_before(); if ( $woo_options['woo_post_content'] !=

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.