1

我有两个mysql表

我的标签

  1. ID
  2. 用户代码
  3. tab_id
  4. 菲德
  5. 表ID

标签

  1. tab_id
  2. 标题
  3. 用户代码
  4. 访问类型
  5. 问题

两个表都将 tab_id 作为主键并使用相同的值。我想列出 mytabs 表中的数据,该表在 Tabs Table 和 access_type = 1 中具有相同的 tab_id。我不想列出 Tabs 中的记录,如果该 Tab 具有 access_type 1,则查询应该只从 Tabs 验证,那么它应该列出

可能吗?我正在尝试的是它没有返回任何东西。

 $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"
4

2 回答 2

2

您可以使用INNER JOIN.

select * from tabs INNER JOIN myTabs ON tabs.tab_id = myTabs.tab_id

where并在子句中附加其他条件。

而 INNER JOIN 所做的是仅当两个表中至少有一行与连接条件匹配时才返回行。

于 2013-04-27T04:36:48.597 回答
1

使用此查询

SELECT * FROM Shortcut s
INNER JOIN Tabs t
ON s.tab_id=t.tab_id
WHERE t.access_type=1 AND t.usercode = '$usercode'
于 2013-04-27T04:35:55.790 回答