<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How list all USERs FROM a especific GROUP USING SQL? in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/62754#M2803</link>
    <description>&lt;P&gt;This solution seems to have been answered by an AI.&lt;BR /&gt;I need to know how create a SELECT for create this tables:&amp;nbsp;&lt;SPAN&gt;USERS, GROUPS and GROUP_USERS.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2024 14:13:11 GMT</pubDate>
    <dc:creator>Sardenberg</dc:creator>
    <dc:date>2024-03-06T14:13:11Z</dc:date>
    <item>
      <title>How list all USERs FROM a especific GROUP USING SQL?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/62594#M2800</link>
      <description>&lt;P&gt;I want to list, using sql editor, &lt;STRONG&gt;all users name from a specific group&lt;/STRONG&gt;.&lt;BR /&gt;Reading documentation, I only learned how to show the groups or the users, using simples filters, like:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;SHOW&lt;/SPAN&gt; &lt;SPAN class=""&gt;GROUPS&lt;/SPAN&gt; &lt;SPAN class=""&gt;LIKE&lt;/SPAN&gt; &lt;SPAN class=""&gt;'*XPTO*'&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;SHOW&lt;/SPAN&gt; &lt;SPAN class=""&gt;GROUPS&lt;/SPAN&gt; &lt;SPAN class=""&gt;WITH&lt;/SPAN&gt; &lt;SPAN class=""&gt;USER&lt;/SPAN&gt; &lt;SPAN class=""&gt;`&lt;/SPAN&gt;&lt;SPAN class=""&gt;test&lt;/SPAN&gt;&lt;SPAN class=""&gt;@&lt;/SPAN&gt;&lt;SPAN class=""&gt;gmail&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;com&lt;/SPAN&gt;&lt;SPAN class=""&gt;`&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;SHOW&lt;/SPAN&gt; &lt;SPAN class=""&gt;USERS&lt;/SPAN&gt; &lt;SPAN class=""&gt;LIKE&lt;/SPAN&gt; &lt;SPAN class=""&gt;'*gus*'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I would like to create something like:&lt;BR /&gt;select users_name from USERS where group_name = "XPTO_GROUP";&lt;BR /&gt;or&lt;BR /&gt;SHOW USERS WHERE GROUP "xpto_group";&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 14:36:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/62594#M2800</guid>
      <dc:creator>Sardenberg</dc:creator>
      <dc:date>2024-03-04T14:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: How list all USERs FROM a especific GROUP USING SQL?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/62754#M2803</link>
      <description>&lt;P&gt;This solution seems to have been answered by an AI.&lt;BR /&gt;I need to know how create a SELECT for create this tables:&amp;nbsp;&lt;SPAN&gt;USERS, GROUPS and GROUP_USERS.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 14:13:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/62754#M2803</guid>
      <dc:creator>Sardenberg</dc:creator>
      <dc:date>2024-03-06T14:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: How list all USERs FROM a especific GROUP USING SQL?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/91697#M4357</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/101636"&gt;@Sardenberg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;This solution seems to have been answered by an AI.&lt;BR /&gt;I need to know how create a SELECT for create this tables:&amp;nbsp;&lt;SPAN&gt;USERS, GROUPS and GROUP_USERS.&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Databricks notebook source
from pyspark.sql.functions import lit

# COMMAND ----------

df_groups = spark.sql("""SHOW GROUPS""")

# COMMAND ----------

df_users = spark.sql("""SHOW USERS""")

# COMMAND ----------


result = spark.createDataFrame([], "name: string, directGroup: boolean, user: string")
for user in df_users.collect():
    df_user_groups = spark.sql(f"""SHOW GROUPS WITH USER `{user.name}`""").withColumn("user", lit(user.name))
    result = result.unionAll(df_user_groups)

# COMMAND ----------

display(result) # Here you can create temp view and select data&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will work fine if groups added to workspace.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 08:46:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/91697#M4357</guid>
      <dc:creator>arch_db</dc:creator>
      <dc:date>2024-09-25T08:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How list all USERs FROM a especific GROUP USING SQL?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/93304#M4400</link>
      <description>&lt;P&gt;I don't think it's possible yet. Unfortunately, I look in all system tables and command and didn't found this kind of things.&lt;/P&gt;&lt;P&gt;But with a Python notebook, like what did the AI, you can reconstruct it:&lt;/P&gt;&lt;P&gt;first you list all the users with&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;SHOW&lt;/SPAN&gt; USERS&lt;/PRE&gt;&lt;P&gt;then you loop for all users to get its groups with:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;SHOW&lt;/SPAN&gt; &lt;SPAN class=""&gt;GROUPS&lt;/SPAN&gt; &lt;SPAN class=""&gt;WITH&lt;/SPAN&gt; &lt;SPAN class=""&gt;USER `{user.name}`&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;And you can reconstruct the list of users in each groups like that, and put it in a delta table with a create table.&lt;/P&gt;&lt;P&gt;With this table you can easily list all users in a specific group in a SQL request. You "just" need to run your python notebook regularly to update your user-group table.&lt;/P&gt;&lt;P&gt;Due to the special type of command that this is, you can't (to my knowledge) do that kind of thing directly in SQL, (can't "SELECT * FROM SHOW ..." for example), and there is no specific command for that, so it's a little laborious, especially if you have a lot of users and groups.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 14:03:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-list-all-users-from-a-especific-group-using-sql/m-p/93304#M4400</guid>
      <dc:creator>Robin63</dc:creator>
      <dc:date>2024-10-09T14:03:30Z</dc:date>
    </item>
  </channel>
</rss>

