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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:03:13+00:00 2026-05-23T20:03:13+00:00

MySQL table1: +—-+——–+———+——+ | id | itemid | type | name | +—-+——–+———+——+ |

  • 0

MySQL

table1:

+----+--------+---------+------+
| id | itemid |   type  | name |
+----+--------+---------+------+
| 1  |   1    | product |  t   |
+----+--------+---------+------+
| 2  |   2    | product |  t   |
+----+--------+---------+------+
| 3  |   3    | service |  t   |
+----+--------+---------+------+

table2:

+--------+---------+
| itemid | display |
+--------+---------+
|   1    |    1    |
+--------+---------+

PHP

$a = mysql_query("SELECT * FROM `table1` WHERE `name` LIKE '%t' ....");

I want to modify the query above and also test:

If type = product then itemid should not be included in table2 where display = 1.

Further Explanation:

So, I want to see whether or not the row in table1 that matches t is a product.

If it is not a product (i.e. service), just go ahead and display it.

If it is a product, I want to further check whether or not its itemid is included in table2

If it is included, then don’t display it.

If it is not included, then display it.

Sorry, I don’t know how else to explain it. :/

  • 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-23T20:03:14+00:00Added an answer on May 23, 2026 at 8:03 pm

    If I understand you correctly, you want to exclude rows whose type = ‘product’:

    SELECT * FROM table1 t1, table2 t2
    WHERE t1.itemid = t2.itemid 
    AND t1.id = '1' 
    AND t1.type <> 'product'
    

    (If that’s not what you want, IMHO some further explanation is necessary)

    UPDATE: to exclude all whose type = ‘product’ having a matching row in table2:

    SELECT * FROM table1 t1
    WHERE t1.id = '1' 
    AND (t1.type <> 'product' OR NOT EXISTS (
     SELECT NULL from table2 t2 
     WHERE t1.itemid = t2.itemid )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a mysql query like this: SELECT A.ID, A.NAME, B.ID, B.NAME FROM table1
MySQL - is it legal to do 'SELECT table1.*,table2.column FROM table1,table2' ?
Is this possible in mysql? update table1 set column1 = (select column1 from table2
<?php $query = SELECT * FROM table1; $result = mysql_query($query) or die (Query Failed:
I have the following MySql query: select t1.* from Table1 t1 inner join Table2
I am confused here. $sql_n = mysql_query(SELECT * FROM table1 WHERE n='{$row['n']}'); $row_n =
I have a mysql database with two tables: table1 (id, name, emailid) table2 (id,
I have this query with MySQL: select * from table1 LIMIT 10,20 How can
I am new to MySql/PHP. Each row from Database1.table1 has to be read and
In MySQL you can use the syntax DELETE t1,t2 FROM table1 AS t1 INNER

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.