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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:03:30+00:00 2026-05-11T05:03:30+00:00

I have two tables in a SQLite DB, INVITEM and SHOPITEM. Their shared attribute

  • 0

I have two tables in a SQLite DB, INVITEM and SHOPITEM. Their shared attribute is ItemId and I want to perform an INNER JOIN. Here’s the query:

    SELECT  INVITEM.CharId AS CharId,              INVITEM.ItemId AS ItemId        FROM  (INVITEM as INVITEM  INNER JOIN  SHOPITEM AS SHOPITEM          ON  SHOPITEM.ItemId = INVITEM.ItemId)      WHERE  ItemId = 3; 

SQLite doesn’t like it :

SQL error: ambiguous column name: ItemId 

The error goes away if I write WHERE INVITEM.ItemId = 3, but since the WHERE condition is more or less user-specified, I rather make it work without having to specify the table. NATURAL JOIN seems to solve the issue, but I’m not sure if the solution is general enough (ie I could use in this case, but I’m not sure if I can use in every case)

Any alternate SQL syntax that would fix the problem?

  • 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-11T05:03:30+00:00Added an answer on May 11, 2026 at 5:03 am

    I would steer clear of allowing the user to write SQL clauses directly. This is the source of SQL Injection vulnerabilities.

    If you need the query to be flexible, try parsing the user’s input and adding the appropriate where clause.

    Here is some C# code to show the general idea

    // from user input string user_column = 'ItemID'; string user_value = '3';  string sql = 'SELECT INVITEM.CharId AS CharId, INVITEM.ItemId AS ItemId FROM (INVITEM as INVITEM INNER JOIN SHOPITEM AS SHOPITEM ON SHOPITEM.ItemId = INVITEM.ItemId) ';  if (user_column == 'ItemID') {     // using Int32.Parse here to prevent rubbish like '0 OR 1=1; --' being entered.     sql += string.Format('WHERE INVITEM.ItemID={0}',Int32.Parse(user_value)); } 

    Obviously if you’re dealing with more than one clause, you’d have to substitute AND for WHERE in subsequent clauses.

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

Sidebar

Related Questions

sqlite3 I have two tables. One contains some lists and the other contains each
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two tables in my database, table1 and table2. They are identical. But
I have two tables in a legacy database... tblParentTable (int id, string specialIdentifier, ...)
I have two python scripts that have to run simultaneously because they interact with
I have found several topics with this title, but none of their solutions worked
I have an iPhone app and one of my users found a really strange
We're designing an Android app that has a lot of data (customers, products, orders...),
Okay so right now I'm working on a program that has a whole bunch

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.