MySQL check if value already exists between two tables

sgspragg

I have two tables (items and sub_items). Both tables have an asset_number column. I need a query that will let me add a new item only if the given asset_number is not present in either of the two tables.

OHHO

Can you be more specific on the fields?

Does your sub_items table have itemsId?

If yes, I think you can join those two tables and search for the new item?

Something like this:

SELECT I.item_id AS item_items_id, SI.item_id AS subitem_items_id FROM items I
INNER JOIN sub_items SI ON I.item_id = SI.item_id AND I.asset_number = SI.asset_number
WHERE I.item_id = -- if your new item has an item_id you can search it

If the new item doesn't have an ID, then maybe you can search by using a item name if there is a column?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Query mySQL to check if user already exists in two tables

postgres query multiple tables to check if a value already exists

Check if combination of items already exists in many-to-many MySQL tables

Check value between two tables (MS ACCESS)

Between two tables how does one SELECT the table where the id of a specific value exists mysql (duplicate)

Check if an value already exists in database

Check value already exists or not in Firebase?

Check if a value exists between two array indexes in PHP

check given date exists between two date column in mysql

Check if differences between elements already exists in a list

Insert two tables value to already exist tables

Check if the value already exists in the database using Laravel

Check if value already exists within list of dictionaries?

How to check if submitted element value already exists?

how to check if value already exists in txt file

check if a textbox value already exists in a listbox

Check if value already exists on an object javascript

check if value already exists in multimap c++

React - Check if a value already exists in an array?

Check if randomly generated value already exists in hash

Check whether the data already exists in MySQL

check username and email already exists in php mysql

Check if one row exists in two tables

MySQL updating a field with comma if a value already exists

Mysql - Check if id exists in foreign tables

postgresql - Check if a relationship exists between tables using case and exists

Comparing two tables in laravel to check if a row exists in the tables

join between two tables in mysql

How to check a date exists in between two dates?