logo
down
shadow

Select query with comma and join


Select query with comma and join

By : user2952463
Date : November 19 2020, 01:01 AM
To fix this issue I have tbl A and tbl B as below and I would like to get their names which is seperated by comma but I am not getting in the format I am looking for. , Try this:
code :
SELECT a.user, a.category, b.username 
FROM tblA a 
JOIN tblB b ON find_in_set(b.userid,a.user) 
WHERE FIND_IN_SET(2,a.user)
ORDER BY a.user;
|  USER | CATEGORY | USERNAME |
|-------|----------|----------|
| 1,2,3 |        1 |        A |
| 1,2,3 |        1 |        B |
| 1,2,3 |        1 |        C |
|     2 |        1 |        B |


Share : facebook icon twitter icon
Is a query with table separated by comma a cross join query?

Is a query with table separated by comma a cross join query?


By : He Yuxin
Date : March 29 2020, 07:55 AM
will help you It would be a cross join if there wasn't a WHERE clause relating the two tables. In this case it's functionally equivalent to an inner join (matching records by id_rel and id)
It's an older syntax for joining tables that is still supported in most systems, but JOIN syntax is largely preferred.
How to optimize a MySQL SELECT query with a LEFT JOIN in main query and an INNER JOIN in subquery?

How to optimize a MySQL SELECT query with a LEFT JOIN in main query and an INNER JOIN in subquery?


By : Paul Onema
Date : March 29 2020, 07:55 AM
I wish this helpful for you One possible way to do this would be to use a pair of LEFT joins, and then determine whether to return B.adid depending on whether a match has been found on C:-
code :
SELECT A.*, 
    IF(C.bfid IS NULL, NULL, B.bid), 
    IF(C.bfid IS NULL, NULL, C.cid), 
    IF(C.bfid IS NULL, NULL, C.bfid)
FROM A
LEFT OUTER JOIN B ON A.bfid = B.bid
LEFT OUTER JOIN C ON B.bid = C.bfid
Sql Query Join on Comma Separated Value

Sql Query Join on Comma Separated Value


By : onsentamago
Date : March 29 2020, 07:55 AM
I wish this helpful for you Here is a simple inline approach if you don't have or want a Split/Parse UDF
Example
code :
Select A.[Key Part 1]
      ,A.[Key Part 2]
      ,A.[Key Part 3]
      ,B.*
 From YourTable A
 Cross Apply (
                Select [Values]   = LTrim(RTrim(X2.i.value('(./text())[1]', 'varchar(max)')))
                      ,[Sequence] = Row_Number() over (Order By (Select null))-1
                From  (Select x = Cast('<x>' + replace(A.[Values],',','</x><x>')+'</x>' as xml)) X1 
                Cross Apply x.nodes('x') X2(i)
             ) B
Select A.[Key Part 1]
      ,A.[Key Part 2]
      ,A.[Key Part 3]
      ,[Values] = B.RetVal
      ,[Sequence] = B.RetSeq-1
 From @YourTable A
 Cross Apply [dbo].[udf-Str-Parse-8K](A.[Values],',') B
CREATE FUNCTION [dbo].[udf-Str-Parse-8K] (@String varchar(max),@Delimiter varchar(25))
Returns Table 
As
Return (  
    with   cte1(N)   As (Select 1 From (Values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N(N)),
           cte2(N)   As (Select Top (IsNull(DataLength(@String),0)) Row_Number() over (Order By (Select NULL)) From (Select N=1 From cte1 a,cte1 b,cte1 c,cte1 d) A ),
           cte3(N)   As (Select 1 Union All Select t.N+DataLength(@Delimiter) From cte2 t Where Substring(@String,t.N,DataLength(@Delimiter)) = @Delimiter),
           cte4(N,L) As (Select S.N,IsNull(NullIf(CharIndex(@Delimiter,@String,s.N),0)-S.N,8000) From cte3 S)

    Select RetSeq = Row_Number() over (Order By A.N)
          ,RetVal = LTrim(RTrim(Substring(@String, A.N, A.L)))
    From   cte4 A
);
--Orginal Source http://www.sqlservercentral.com/articles/Tally+Table/72993/
--Select * from [dbo].[udf-Str-Parse-8K]('Dog,Cat,House,Car',',')
--Select * from [dbo].[udf-Str-Parse-8K]('John||Cappelletti||was||here','||')
SQL Query INNER JOIN or LEFT JOIN Want to select posts from specific categories in Wordpress but do NOT select those of

SQL Query INNER JOIN or LEFT JOIN Want to select posts from specific categories in Wordpress but do NOT select those of


By : user2458989
Date : March 29 2020, 07:55 AM
Hope that helps Selecting specific categories works fine: , I think you want:
code :
SELECT wp.ID, wp.post_content, wp.post_title
FROM wp_posts wp
WHERE NOT EXISTS (SELECT 1
                  FROM  wp_term_relationships tr 
                  WHERE tr.object_id = wp.id AND
                        tr.term_taxonomy_id IN (17, 19)
                 );
SELECT wp.ID, wp.post_content, wp.post_title
FROM wp_posts wp JOIN
     wp_term_relationships tr 
     ON tr.object_id = wp.id
GROUP BY wp.ID, wp.post_content, wp.post_title
HAVING SUM( CASE WHEN tr.term_taxonomy_id IN (17, 19) THEN 1 ELSE 0 END) = 0;
SQL Select Query With FIND_IN_SET Or Any things else to find comma separated values in a column with comma separeted val

SQL Select Query With FIND_IN_SET Or Any things else to find comma separated values in a column with comma separeted val


By : shubhajoy das
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have one column having comma separated values: , Use it like this
Related Posts Related Posts :
  • MySQL comma separated field query
  • Why does the same exact query produce 2 different MySQL explain results?
  • Suppress warning output in bash
  • Doctrine "on update CURRENT_TIMESTAMP" annotation (Symfony2)
  • Designing "Friend" relationships across two mysql tables
  • Importing sql file using phpmyadmin in EasyPHP
  • Easy PHP and mysql ..php cannot see database on local pc (all works on server)
  • 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
  • Get all rows that match another attribute in the same table
  • MySQL statement to get min value with max ID
  • DATEDIFF Current/Date for Last Record
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org