Reputation: 171
I have two mysql tables
myTabs
Tabs
both tables have tab_id as primary key and use the same value. I want to list the data from mytabs table which has same tab_id in Tabs Table and access_type = 1. I dont want to list the records from Tabs the query should only validate from Tabs if that Tab has access_type 1 then it should list
Is it possible? What I am trying is it has not returned anything.
$mysql = "select mytabs.*, tabs.* FROM mytabs, tabs where mytabs.usercode='$usercode' and (mytabs.fid IS NULL || mytabs.fid='0') and tabs.access_type = '1' order by mytabs.tablistid asc"
Upvotes: 1
Views: 113
Reputation: 27382
You can use INNER JOIN
.
select * from tabs INNER JOIN myTabs ON tabs.tab_id = myTabs.tab_id
and append other condition in where
clause.
And what INNER JOIN do is return rows only when there is at least one row from both tables that matches the join condition.
Upvotes: 2
Reputation: 28771
Use this query
SELECT * FROM Shortcut s
INNER JOIN Tabs t
ON s.tab_id=t.tab_id
WHERE t.access_type=1 AND t.usercode = '$usercode'
Upvotes: 1