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

  • Home
  • SEARCH
  • 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 6598511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:21:29+00:00 2026-05-25T18:21:29+00:00

I only know the bare min when it comes to SQL so please treat

  • 0

I only know the bare min when it comes to SQL so please treat me as a complete noob!

I have a table which has many rows but some of them can pair up by the id and I want return array of those rows merged.

 post_id  # meta_name # meta_value  #     
======================================
   1      #   bar     #    44       #
   1      #   foo     #    on       #
   2      #   bar     #    1        #
   2      #   foo     #    on       #
   3      #   bar     #    1        #
   3      #   foo     #    off      #

as a scaled down version, imagine the above of my table and I am aiming to return 2 results of

   1    #   foo    #  bar    #   44   #  on
   2    #   foo    #  bar    #   1    #  on

based on that the ids are related and that c2 has the value of ‘on’

my attempt was the following from some reading but not getting anywhere

SELECT 
    t1.post_id, t2.post_id, t1.meta_name, t2.meta_name, t1.meta_value, t2.meta_value 
FROM 
    `ecom_page_meta` t1 
JOIN 
    `ecom_page_meta` t2 
ON 
    t1.post_id = t2.post_id 
WHERE 
    t1.meta_name = 'featured-products' 
AND 
    t1.meta_value = 'on'

any help would be muchly appreciated

** EDIT **

I thought Id just post the syntax which worked nicely below thanks to the answer below:

SELECT L.post_id, L.meta_name, R.meta_name, L.meta_value, R.meta_value
FROM `ecom_page_meta` L
INNER JOIN ecom_page_meta R
    ON L.post_id = R.post_id
    AND L.meta_name = 'featured-products-order' 
    AND R.meta_value = 'on' 
WHERE R.meta_name = 'featured-products' 
ORDER BY L.meta_value 
DESC

THanks again.

  • 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-25T18:21:30+00:00Added an answer on May 25, 2026 at 6:21 pm

    Create test data:

    SQL> create table ecom_page_meta (post_id number not null
      2      , meta_name varchar2(15) not null
      3      , meta_value varchar2(15) not null);
    
    Table created.
    
    SQL> insert into ecom_page_meta values (1, 'bar', '44');
    
    1 row created.
    
    SQL> insert into ecom_page_meta values (1, 'foo', 'on');
    
    1 row created.
    
    SQL> insert into ecom_page_meta values (2, 'bar', '1');
    
    1 row created.
    
    SQL> insert into ecom_page_meta values (2, 'foo', 'on');
    
    1 row created.
    
    SQL> insert into ecom_page_meta values (3, 'bar', '1');
    
    1 row created.
    
    SQL> insert into ecom_page_meta values (3, 'foo', 'off');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    

    Query to give results matching OP’s sample:

    SQL> select L.post_id, L.meta_name, R.meta_name, L.meta_value, R.meta_value
      2  from ecom_page_meta L
      3  inner join ecom_page_meta R
      4      on L.post_id = R.post_id
      5      and L.meta_value <> 'on'
      6      and R.meta_value = 'on'
      7  where L.meta_name = 'bar';
    
       POST_ID META_NAME       META_NAME       META_VALUE      META_VALUE
    ---------- --------------- --------------- --------------- ---------------
             1 bar             foo             44              on
             2 bar             foo             1               on
    

    I still do not know what WHERE t1.meta_name = 'featured-products' has do to do with anything since no sample data includes t1.meta_name of the string ‘featured-products’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I only know Wordpress and have started to seek another alternative framework, Zend. I
Is there a ActionScript-version of JavaScript's Canvas.clearRect()? I only know graphics.drawRect(...) which allows me
i have a scroll view which represents a map, it has pins on it,
Forgive me if my understanding of this topic has some shortcomings, I only know
We have a case where we only know the icon for a menu item
I have XmlDocument. I don't know XPath, I only know that this xml document
I have a GridView with pictures/text, loaded from different servers (I only know the
I only know a small amount about .NET MVC and haven't used it barely
I only know of one way: Right click and click 'delete me' How else
I only know that the difference between hashmap and map is that hashmap is

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.