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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:43:54+00:00 2026-06-06T13:43:54+00:00

I have a database that which contains two tables, links and tour. Tour is

  • 0

I have a database that which contains two tables, links and tour. Tour is defined as

+----+-------------+-----+-----+--------+---------+-------+---------+
| ID | FileName    | Lat | Lon | Name   | Heading | Width | Height  |
+----+-------------+-----+-----+--------+---------+-------+---------+

and links is defined as

+-----+------------+--------+
| ID  | locationID | linkID |
+-----+------------+--------+

links.locationID is a foreign key to tour.ID. What I want to do is grab all the links that match to a specific tour.name

Right now, I have to run these two queries and use the ID of the first as a variable for the second

SELECT * FROM tour WHERE tour.name = 'name'

SELECT * FROM tour
  INNER JOIN links ON tour.ID = links.linkID 
  WHERE links.locationID = ID of first query

How can I adapt this to a single search?

I’ve tried a subquery:

SELECT * FROM tour 
  INNER JOIN links ON tour.ID = links.linkID 
  WHERE links.locationID = ( SELECT * FROM tour WHERE tour.name = 'name')

This gives me an error 1241 saying that operand should contain one column.

I’ve looked up some examples of subqueries, but hey all lack the inner join statement I’m using. What modifications are necessary to this query?

  • 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-06T13:43:55+00:00Added an answer on June 6, 2026 at 1:43 pm
    SELECT links.*, tour.*
    FROM links
    JOIN tour ON tour.ID = links.linkID
    JOIN tour AS location ON location.ID = links.locationID -- you must create an alias, in order to refer to this table without ambiguity
    WHERE location.name = 'name';
    

    As for your version with subquery, you could do:

    SELECT * FROM tour 
    INNER JOIN links ON tour.ID = links.linkID 
    WHERE links.locationID = (
        SELECT ID -- "operand should contain one column"
        FROM tour WHERE tour.name = 'name'
    );
    

    But prefer the first option.

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

Sidebar

Related Questions

I have a database that has two tables, one of which contains a foreign
I have two simple tables in my database. A card table that contains Id,
I have my own custom Content Provider that loads a database which contains the
Should a database table that contains two columns that are foreign keys have a
I have a database with two tables. One of the tables contains users, the
I have two database tables: 'MyTable' which has a standard auto-incrementing primary key integer
In my MySQL database I have two tables: 'orders' and 'orders_lines'. Orders contains info
I have two tables that are related, which, for the purpose of this question,
I am beginner in SQL, I have a simple MySQL database which contains two
I have a table in database that is having some fields one of which

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.