MySQL, get data based on two tables

sql select from multiple tables without join
mysql> select from two tables at once
how to fetch data from two tables in mysql using php
how to retrieve data from two tables with one sql statement
how to get common records from two tables in mysql
mysql> select from multiple tables
how to fetch data from three tables in mysql using php
mysql join

I am trying to get data based on two tables.

My tables look like this:

table1:
    id | value | email

table2:
    id | category | value | email

I am trying to get all values of table 1, as long as they are not in table2 with the category of my variable (myVar).

Example: Our Variable is "DontPickMe". In table1 we have value 1,2,3. In table2 we have 1,2. Number 1 got category "keepMe" and number 2 got category "DontPickMe" (our variable). The result should now be: 1,3.

In the example (result should be 1,3):

table1:
        id | value | email
               1
               2
               3
table2:
        id | category | value | email
             keepMe       1
            DontPickMe    2

I tried the below but it is wrong.. How can I achieve this?

let sql = 'SELECT value FROM table1 WHERE NOT EXISTS (SELECT category FROM table2 WHERE category = ?)';

    connection.query(sql, [myVar], function(error, result) {
        if (error) throw error;
        console.log(result)

So you can use this to get desired result

   let sql = 'SELECT value FROM table1 WHERE value NOT IN (SELECT value FROM table2 WHERE category = ?)';

  connection.query(sql, [myVar], function(error, result) {
    if (error) throw error;
    console.log(result)

Retrieving Records from Multiple Tables, Get down and dirty with mySQL by learning the basics of SQL syntax and useful It does no good to put records in a database unless you retrieve them If a SELECT statement names multiple tables in the FROM clause the ability to delete or update records in one table based on the contents of another. Get data from multiple tables based on condition. Viewed 26 times 1. I need to get some data from 3 different mysql tables as follows.


SELECT distinct value FROM table1 left join table2 on table1.category=table2.category WHERE table1.category = ? and table2.category is null

MySQL Select Data from two Tables in 1 Query with out specifying , Don't use the *, instead specify all column names you want to extract. Good practice in a multiple table query is to specify the columns table as well: item_inventory. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Get different set of data based on value on two tables


let sql = 'SELECT DISTINCT value FROM table1 LEFT JOIN table2 on table1.value = table2.value WHERE category = ?';

    connection.query(sql, [myVar], function(error, result) {
        if (error) throw error;
        console.log(result)

Sorry if wrong. :D

Get Data from Multiple Tables, Based on the join conditions, Oracle combines the matching pair of rows and displays the one which satisfies the join condition. Joins are classified as below. Anyway I have two tables I'm trying to get a count of records from based on a field in one table that doesn't exist in another table. Here is the layout. comments table has a comment_post_id field posts table has an ID field The data in each of these fields are the same in that they are related to posts a user submits.


How to Join Two Tables in MySQL, Let us start by adding a new table in our database which will contain the message along Now let us get started by joining these two tables. Below is an excerpt from an SQL query I am doing with php and it's working as I expected and wanted however for my own curiosity's sake I want to know how to only select the data I need in a multi


fetch data from multiple tables using single query, For the above requirement, following query should work. SELECT j.jobid, j.name, af.id, af.kind, af.location FROM jobs j INNER JOIN  Joins are the most important thing in relational databases. They are used to join two or more different tables on a point in which both the tables match the same value and property. There are four easy ways to join two or more tables: Inner Join; Left Join; Right Join; Union; Cross Join or Cartesian Product; Self Join; FULL OUTER JOIN


WL#358: Selecting into multiple tables, Based on this e-mail from one user (excerpt only): Multitable SELECT 2: Queries from multiply tables could still be updateable easily from client apps if they could be sent to the client before the main result data, and while doing the other  To check the data, we have to compare two tables, one in the new database and one in the legacy database and identify the unmatched records. Suppose, we have two tables: t1 and t2. The following steps compare two tables and identify the unmatched records: First, use the UNION statement to combine rows in both tables; include only the columns