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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:34:51+00:00 2026-05-10T16:34:51+00:00

Say I have two tables I want to join. Categories: id name ———- 1

  • 0

Say I have two tables I want to join. Categories:

id   name ---------- 1    Cars 2    Games 3    Pencils 

And items:

id   categoryid   itemname --------------------------- 1    1            Ford 2    1            BMW 3    1            VW 4    2            Tetris 5    2            Pong 6    3            Foobar Pencil Factory 

I want a query that returns the category and the first (and only the first) itemname:

category.id category.name item.id item.itemname ------------------------------------------------- 1           Cars          1       Ford 2           Games         4       Tetris 3           Pencils       6       Foobar Pencil Factory 

And is there a way I could get random results like:

category.id category.name item.id item.itemname ------------------------------------------------- 1           Cars          3       VW 2           Games         5       Pong 3           Pencils       6       Foobar Pencil Factory 

Thanks!

  • 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. 2026-05-10T16:34:52+00:00Added an answer on May 10, 2026 at 4:34 pm

    Just done a quick test. This seems to work:

    mysql> select * from categories c, items i     -> where i.categoryid = c.id     -> group by c.id; +------+---------+------+------------+----------------+ | id   | name    | id   | categoryid | name           | +------+---------+------+------------+----------------+ |    1 | Cars    |    1 |          1 | Ford           | |    2 | Games   |    4 |          2 | Tetris         | |    3 | Pencils |    6 |          3 | Pencil Factory | +------+---------+------+------------+----------------+ 3 rows in set (0.00 sec) 

    I think this would fulfil your first question. Not sure about the second one – I think that needs an inner query with order by random() or something like that!

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

Sidebar

Related Questions

Say I have two tables called A (fields: id, phase, name) and B(fields: id,
I have two tables that I need to join... I want to join table1
I have two tables to join with a column (say emp_id ).. if emp_id
Say I have two tables, 'cars' and 'properties', linked by table 'car_properties'. I can
lets say I have two tables: Persons (P_Id, Name) and Orders (O_Id, OrderNo, P_Id)...
I have 3 tables. news: id title categories: id name newsEachCategories: postId categoryId Table
Let's say I have two tables with a one-to-many relationship. I want to create
Let's say I have two tables, and both their primary identifiers use the name
Say I have two tables: object id name object_event id object_id type date I
I have two tables, Table1 and Table2 . I want to perform, say, a

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.