logo
down
shadow

Get all rows that match another attribute in the same table


Get all rows that match another attribute in the same table

By : user2955359
Date : November 22 2020, 10:38 AM
This might help you I have this table (called posts): , Use self Join
code :
SELECT b.post_id,
       b.reply_to,
       b.user_id
FROM   Posts a
       JOIN Posts b
         ON a.post_id = b.reply_to
WHERE  a.user_id = 1 
SELECT *
FROM   Posts p
WHERE  EXISTS (SELECT 1
               FROM   Posts p1
               WHERE  p1.user_id = 1
                      AND p.reply_to = p1.post_id); 


Share : facebook icon twitter icon
Specific query to select all rows in Table A that don't match criteria defined in rows of Table B?

Specific query to select all rows in Table A that don't match criteria defined in rows of Table B?


By : Andrey Vorkachev
Date : March 29 2020, 07:55 AM
this will help Why are you storing data like that? Inquiring minds want to know.
However, you might try something along these lines:
code :
select *
from entries e
where not exists ( select *
                   from criteria c
                   where e.tuple like           case coalesce( unit    , '' ) when '' then '%' else unit    end
                                      + ' / ' + case coalesce( product , '' ) when '' then '%' else product end
                                      + ' / ' + case coalesce( part    , '' ) when '' then '%' else part    end
                 )
Returning all parent table rows but return null for child table rows that don't match the WHERE clause with MYSQL

Returning all parent table rows but return null for child table rows that don't match the WHERE clause with MYSQL


By : PayalH
Date : March 29 2020, 07:55 AM
Does that help Hi there I'm stuck on a problem with a personal website I'm building. The page is a user's dashboard that has a list of all the classes on the system. That table is called 'classes' and it is the parent table of 'class_reponses' which is a table that records if the user has either started, finished or failed to finish the class. 'class_responses' has a user_id in it. I'm trying to build a query that will list all of classes rows and simply have null fields when class_reponses user_id does not match the given id. , Put the conditions on a left joined table in the ON clause.
code :
SELECT * FROM classes AS c
LEFT JOIN class_responses AS cr
ON c.id = cr.class_id and cr.user_id = 7
Check rows in first table, compare them with rows from the second table and output a match

Check rows in first table, compare them with rows from the second table and output a match


By : Vinzenz Gregor Eck
Date : March 29 2020, 07:55 AM
With these it helps I made my story shorter, as requested.
code :
SELECT *
FROM Timetable t
WHERE in_dates = 0 OR
  (
    in_dates = 1 AND
    EXISTS (
     SELECT 1
     FROM Dates d
     WHERE d.subject = t.subject AND
       d.date = t.date
    )
  )
Selecting rows from Parent Table only if multiple rows in Child Table match

Selecting rows from Parent Table only if multiple rows in Child Table match


By : Sergio Ramos
Date : March 29 2020, 07:55 AM
To fix this issue This very simple query will do the trick in a single scan, and doesn't require you to violate First Normal Form by storing multiple values in a string (shudder).
code :
SELECT T.GameID
FROM Turns AS T
WHERE
   (T.Turn = 1 AND T.Place = 1)
   OR (T.Turn = 2 AND T.Place = 4)
GROUP BY T.GameID
HAVING Count(*) = 2;
How do i in mysql match all rows in table A with all rows in table b based on the nearest longitude and latitude point?

How do i in mysql match all rows in table A with all rows in table b based on the nearest longitude and latitude point?


By : Lau Ren
Date : March 29 2020, 07:55 AM
This might help you HI Guys first question here. I have simplified the table structure below to make it more apparent the problem. I am using mysql and I have no idea where to start with this one. I need to find the closest store for each of the customers in my database.
Related Posts Related Posts :
  • MySQL join optimization - bypassing filesort
  • How to Select record with the maximum value in a GROUP BY?
  • MySQL Innodb Full text Proximity Search Gives Horrible Performance
  • MySQL best approach for db normalising, relationships and foreign keys
  • How to update one table based on the count value of another table while matching ids?
  • MAMP Pro 5.1.1-terminates MySQL when quitting
  • SQL - Get date of most votes cast
  • "Fuzzier" search in mysql
  • Tracing mysqld Using SystemTap
  • SELECT + INSERT + Query Cache = MySQL lock up
  • SQL vs. NoSQL for medium complexity search systems
  • SQL Error when creating table
  • Is it possible to write a query to compare rows to other rows in same table?
  • Display all duplicate records based multiple columns
  • summing time column in mysql
  • InnoDB: Cannot open table
  • Why is IN() considered O(logN) operation?
  • Can a deadlock occur on commit?
  • Is there a fast way to do a '%phrase%' search in any DB?
  • Is using an IN over a huge data set a good idea?
  • How can I know if a table is already arranged in ascending order in MySQL?
  • MySQL - Designing database for a simple game
  • Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?
  • what type of password hash? possible mysql hash?
  • MySQL - Using a date range vs functions
  • Using IS NULL and COALESCE in OrderBy Doctrine Querybuilder
  • How to merge MySQL columns into one column if there are empty values in the table?
  • Cardinality Confusion
  • Renaming column multiple ids in SELECT
  • Group all from and to messages per user
  • How to handled the null values in WHERE IN condition in mysql
  • Is it okay to update primary key field to shift a record to the top?
  • Stop query through pdo
  • How to check whether particular value in field in MySQL exists
  • Execute a statement for every table in a database
  • insertion 74G data into mysql table cost more then 2 days, how to improve insert performance
  • Where can I see the differents "Hibernate Console Configurations" in Eclipse
  • MySql | relational database vs non relational database in terms of Performance
  • Exporting mysql database using mysqldump including procedures
  • Trigger MySQL not working
  • How do I update values for individual rows quickly?
  • MySQL join query with multiple where condition
  • MySQL stored procedure is not working
  • MySQL - Order By exact match at the end
  • Select max date or null date from same table MySQL
  • Best solution workaround for needing a mysql event on insert?
  • MySQL select several columns of several tables at the same time without using JOIN
  • Is it more efficient to have a table with one of its columns mostly empty or make a new table and refer to it?
  • mysql data truncated with ñ character
  • MySQL Distinct Active Users for the last month query
  • MySQL statement to get min value with max ID
  • DATEDIFF Current/Date for Last Record
  • What is the logic or procedure for combining multiple DB query's results into one elegant table?
  • Modify TIMESTAMP MySQL for use as Primary Key
  • Django - Efficiently bulk create inherited models
  • MySQL Dual table Join Dual table
  • Ruby on Rails - database where sorted by id
  • MySQL 5.6 : Access denied for user 'root' @ 'localhost' when password contains backslash
  • sql query case dateadd
  • Click on one button multiple times and mySql
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org