Query regarding LIKE clause and Select Statement in SQLworkbench

minesh..

i want to retrieve data from the database by performing eg: following query:

  Select * from Employee emp
inner join Department dept on emp.empid=dept.empid
where dept.OrderID like '%1' OR
      dept.OrderID  like '%,1' OR
      dept.OrderID  like '%,1,%' OR
      dept.OrderID  like '1,%'
order by ..;

** Above conditon is--> 1 OR 2,1 OR 2,1,3 OR 1,2

Instead of '1' in above query,i want to pass select statement (select OrderID from Orders where OrderName= 'ABCD').

I have tried but not getting it syntax wise. Please Anyone can suggest me how to perform this correctly. Thanks.

Giulio De Marco

Try this:

     Select * from Employee emp
    inner join Department dept on emp.empid=dept.empid
    where dept.OrderID like CONCAT('%', (select OrderID from Orders where OrderName= 'ABCD')) OR
          dept.OrderID  like CONCAT('%,', (select OrderID from Orders where OrderName= 'ABCD')) OR
          dept.OrderID  like CONCAT('%,', (select OrderID from Orders where OrderName= 'ABCD'), ',%') OR
          dept.OrderID  like CONCAT((select OrderID from Orders where OrderName= 'ABCD'), ',%')
order by ..;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL: Select statement in a LIKE clause

From Dev

T-SQL help needed regarding CASE statement in SELECT clause

From Dev

T-SQL help needed regarding CASE statement in SELECT clause

From Dev

Using % in like clause of select statement in python

From Dev

mysql query to select user count with Like clause

From Dev

Show and Not show a column in SELECT statement by using WHEN clause or something like this?

From Dev

Like clause and prepared statement

From Dev

Where clause - Not Like Statement

From Dev

Select statement in WHERE clause

From Dev

PostgreSQL - if clause in select statement

From Dev

select statement with where clause

From Dev

Need help tuning a select query to change a Match/Against clause to a Like clause

From Dev

Need help tuning a select query to change a Match/Against clause to a Like clause

From Dev

Codeigniter: Query is returning all rows in table on select/like statement

From Dev

Parameter in SELECT clause for @Query?

From Dev

SQL select query with not not in clause

From Dev

SQL Select Statement LIKE IN

From Dev

Query optimization with LIKE statement

From Dev

Nest With clause inside a select statement

From Dev

using select statement in then clause of case

From Dev

SQLAlchemy SELECT WITH clause/statement (pgsql)

From Dev

select statement in where clause sql

From Dev

Nest With clause inside a select statement

From Dev

SQL select statement in where clause

From Dev

SQL Select Statement Where Clause

From Dev

A simple query regarding the difference between two parameters in the function clause

From Dev

Error regarding aggregate functions or the group by clause in a FOR XML Path query

From Dev

Select Query with IN clause - having duplicate values in IN clause

From Dev

Parameterized IReports, SQL statement with a LIKE clause

Related Related

  1. 1

    MySQL: Select statement in a LIKE clause

  2. 2

    T-SQL help needed regarding CASE statement in SELECT clause

  3. 3

    T-SQL help needed regarding CASE statement in SELECT clause

  4. 4

    Using % in like clause of select statement in python

  5. 5

    mysql query to select user count with Like clause

  6. 6

    Show and Not show a column in SELECT statement by using WHEN clause or something like this?

  7. 7

    Like clause and prepared statement

  8. 8

    Where clause - Not Like Statement

  9. 9

    Select statement in WHERE clause

  10. 10

    PostgreSQL - if clause in select statement

  11. 11

    select statement with where clause

  12. 12

    Need help tuning a select query to change a Match/Against clause to a Like clause

  13. 13

    Need help tuning a select query to change a Match/Against clause to a Like clause

  14. 14

    Codeigniter: Query is returning all rows in table on select/like statement

  15. 15

    Parameter in SELECT clause for @Query?

  16. 16

    SQL select query with not not in clause

  17. 17

    SQL Select Statement LIKE IN

  18. 18

    Query optimization with LIKE statement

  19. 19

    Nest With clause inside a select statement

  20. 20

    using select statement in then clause of case

  21. 21

    SQLAlchemy SELECT WITH clause/statement (pgsql)

  22. 22

    select statement in where clause sql

  23. 23

    Nest With clause inside a select statement

  24. 24

    SQL select statement in where clause

  25. 25

    SQL Select Statement Where Clause

  26. 26

    A simple query regarding the difference between two parameters in the function clause

  27. 27

    Error regarding aggregate functions or the group by clause in a FOR XML Path query

  28. 28

    Select Query with IN clause - having duplicate values in IN clause

  29. 29

    Parameterized IReports, SQL statement with a LIKE clause

HotTag

Archive