1

I have two mysql tables

myTabs

  1. id
  2. usercode
  3. tab_id
  4. fid
  5. tablistid

Tabs

  1. tab_id
  2. title
  3. usercode
  4. access_type
  5. question

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"

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.