PHP Tutorials
- What is MySqli
- mysql query
- mysql query example
- InnoDB
- mysql column Type
- CRUD Example
- Connection Using Function
- mysql keys
- SELECT
- WHERE
- UPDATE
- Count no of Rows
- ALIAS
- AND, AND & OR
- BETWEEN
- COMPARISON OPERATOR
- DELETE
- DELETE LIMIT
- DISTINCT
- EXISTS
- FROM
- GROUP BY
- HAVING
- IN
- INTERSECT
- IS NULL & IS NOT NULL
- LIKE
- NOT
- ORDER BY
- SELECT LIMIT
- SUBQUERY
- TRUNCATE
- UNION && UNION ALL
- Concat & Group_Concat
- mysql Function
- Mysql Insert Id
- MySql Aggregate Function
- Mysql Join
- JOIN in MySql
- Trigger
- Procedure
- Transaction
- views
- Index
- SQL Injection
- Normalization
- Query Bind
- Interview Questions
Important Link
what is exists in mysql?
syntax
EXISTS returns either true or false. The EXISTS is used to check for the existence of rows returned by the subquery.
EXISTS operator returns TRUE if the subquery returns one or more rows.
It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
SELECT column_name
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);
With SELECT Statement
SELECT *
FROM customers
WHERE EXISTS (SELECT *
FROM order_details
WHERE customers.customer_id = order_details.customer_id);
ELECT name, occupation FROM customer
WHERE EXISTS (SELECT * FROM Orders
WHERE customer.customer_id = Orders.customer_id);
With SELECT Statement using NOT EXISTS
SELECT *
FROM customers
WHERE NOT EXISTS (SELECT *
FROM order_details
WHERE customers.customer_id = order_details.customer_id);
With INSERT Statement
INSERT INTO contacts
(contact_id, contact_name)
SELECT supplier_id, supplier_name
FROM suppliers
WHERE EXISTS (SELECT *
FROM orders
WHERE suppliers.supplier_id = orders.supplier_id);
With DELETE Statement
DELETE FROM suppliers
WHERE EXISTS (SELECT *
FROM orders
WHERE suppliers.supplier_id = orders.supplier_id);
Example
SELECT EXISTS(SELECT * from itechxpert WHERE emp_id=101) AS Result;